Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I´d like to link the_post_thumbnail by using the the_permalink.

I do this (It Works without link)

<?php $args = array( 'post_type' => 'xyz', 'posts_per_page' => -1, 'orderby' => 'rand' );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

   the_post_thumbnail('wine-flow', array('class' => 'item'));

endwhile; ?>

And I´d like to do further this: (Syntax Error)

<?php $args = array( 'post_type' => 'xyz', 'posts_per_page' => -1, 'orderby' => 'rand' );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail('wine-flow', array('class' => 'item')); ?>
   </a>

endwhile; ?>

Thanks
ogni

share|improve this question
    
You are mixing html and php code without "escaping" the html code with the php tags: <?php & ?>. Is it only the syntax you have a problem with? –  hampusn Sep 25 '12 at 9:40
add comment

2 Answers 2

up vote 0 down vote accepted

That is because you haven't close php before anchor tag

<?php $args = array( 'post_type' => 'xyz', 'posts_per_page' => -1, 'orderby' => 'rand' );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post(); ?>

   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail('wine-flow', array('class' => 'item')); ?>
   </a>
<?php
endwhile; ?>
share|improve this answer
    
Great - thanks a lot for sharing –  ogni Sep 25 '12 at 10:10
add comment

You need to jump out of PHP after calling $loop->the_post(), because you are writing HTML after that. You also need to jump back into PHP before endwhile; because that is PHP and not HTML.

<?php $args = array( 'post_type' => 'xyz', 'posts_per_page' => -1, 'orderby' => 'rand' );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post(); ?>

   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail('wine-flow', array('class' => 'item')); ?>
   </a>

<?php endwhile; ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.