从缩略图到帖子的链接不起作用

时间:2013-10-06 作者:Kirsty Marks

我正在尝试将我的帖子缩略图链接到它正在拉的帖子,但是它不是作为链接来的: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; ?>
我把实际的div包裹起来,这是正确的方法吗?

谢谢

1 个回复
SO网友:Stubbies

您的页面中可能有多个查询,请确保我们正在处理此查询:

<?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>\';
      }
    }

结束

相关推荐