Reputation: 86
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!
Upvotes: 0
Views: 6465
Reputation: 86
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
Upvotes: 0
Reputation: 7447
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.
Upvotes: 1
Reputation: 320
I think, you forgot the points for string-concatenation (e.g. ' . the_permalink() . ' ... not ' the_permalink ').
Upvotes: 0