0

I have a question using HTML and PHP combined.

I have this little code:

$args = array( 'post_type' => 'program', 'posts_per_page' => 100 );
$loop = new WP_Query( $args );

        while ( $loop->have_posts() ) : $loop->the_post();
        echo '<div class="singleprogram">';
            echo '<div class="entry-title"><a href="'the_permalink()'">';
            the_title();
            echo '</a></div>'; 
            echo '<div class="entry-content">';
            the_content();
            echo '</div></div>';

        endwhile;

If I use this, my page gets all blank. Any ID what I'm doing wrong??

( if i delete the_permalink() and leave a href="" blank then its working but of course it doesn't link to something )

Thanks in advance!

Prophet
  • 32,350
  • 22
  • 54
  • 79
stroeda
  • 86
  • 1
  • 9

3 Answers3

1

You need to properly concatenate the the_permalink() into the string. You can do this using the . operator.

Try this:

echo '<div class="entry-title"><a href="' . the_permalink() . '">';

You can also use the , operator for concatenation inside an echo:

echo '<div class="entry-title"><a href="' , the_permalink() , '">';

which, according to this source, is slightly faster.


Without this, your page "gets all blank" because you have an error:

Parse error: syntax error, unexpected 'the_permalink' (T_STRING), expecting ',' or ';' in ...

Which causes your program to crash.

To avoid the "white screen of death", enable error reporting while developing. This will make debugging problems like this much easier.

Community
  • 1
  • 1
Mark Miller
  • 7,442
  • 2
  • 16
  • 22
  • Thanks for the quick reply! When i use the dots in the script, i get the following result: [link]http://www.octest.nl/testerror/error1.png So the permalink is visible but needs to be placed in the a href – stroeda Jun 18 '14 at 08:29
  • @user2190380 I think that is a different problem. The `.` works fine for the problem as shown. [**See this simple example**](http://codepad.org/qXTN065X) – Mark Miller Jun 18 '14 at 08:45
0

I think, you forgot the points for string-concatenation (e.g. ' . the_permalink() . ' ... not ' the_permalink ').

doh-nutz
  • 310
  • 1
  • 2
  • 10
  • Thanks for the quick reply! When i use the dots in the script, i get the following result: [link]http://www.octest.nl/testerror/error1.png So the permalink is visible but needs to be placed in the a href – stroeda Jun 18 '14 at 08:30
  • Examine the element, using your browser's tools (in case of firefox: right-click and select "inspect element"). Or look at the source-code of the page. Maybe the "the_permalink()"-function creates a complete a-tag, in which case, you might have 2 a-tags inside of each other. - just a guess. – doh-nutz Jun 22 '14 at 09:34
0

Thanks for the information. I found my own solution, don't know why this does work but it works.

echo '<div class="entry-title"><a href="';
        echo the_permalink();
        echo '">';
        echo $post->post_title;
        echo '</a></div>'; 

I had to break up the a href.

Thanks

stroeda
  • 86
  • 1
  • 9