0

i am trying to link my posts thumbnail to the post that it is pulling, however its not coming through as a link :S

<?php
    $carouselPosts = new WP_Query();
    $carouselPosts->query('showposts=3');
    ?>
    <?php while ($carouselPosts->have_posts()) : $carouselPosts->the_post(); ?>
    <a href="<?php the_permalink(); ?>"><div class="recentpostthumbnail"><?php the_post_thumbnail(array(70,70)); ?></div></a>
         <div class="recentpostscontent"><?php the_excerpt(); ?></div>
         <div class="clearfix"></div>
    <?php endwhile; ?>

I put the wrap round the actual div, is this the correct way to do this?

thanks

4
  • Works when I try it. I'd put the anchor around just the image though. You can wrap anchors around block level elements in HTML5 but not before.
    – s_ha_dum
    Commented Oct 6, 2013 at 19:35
  • thanks s_ha_hum i will try that. Maybe its just my chrome being idiotic Commented Oct 6, 2013 at 19:36
  • maybe im being stupid, but its not hyperlinking at all :S Commented Oct 7, 2013 at 11:41
  • Again, your code copied verbatim works for me. Without more information I don't know what to tell you.
    – s_ha_dum
    Commented Oct 7, 2013 at 13:01

1 Answer 1

0

You probably have more than one query in your page, let's make sure we are working with this query:

<?php
    $carouselPosts = new WP_Query();
    $carouselPosts->query('showposts=3');
    // checking if there are posts to show
    if($carouselPosts->posts){ 
       foreach ($carouselPosts->posts as $carouselPost) { 
        echo '<a href="'. get_permalink($carouselPost->ID). '">';
        echo '<div class="recentpostthumbnail">';
          echo get_the_post_thumbnail($carouselPost->ID,array(70,70));
        echo '</div>';
        echo '</a>';
        $excerpt = get_the_excerpt();
        if($excerpt)
             echo '<div class="recentpostscontent">'. $excerpt .'</div>';
        echo '<div class="clearfix"></div>';
      }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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