0

我正在尝试以标签的特色列表样式获取并显示所有帖子my-guide

<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <div class="thumbnail">
    <a href="<?php the_permalink(); ?>">
    <?php the_post_thumbnail(); ?>
    </a>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>

此代码从帖子中获取所有特色图片,但是我试图通过特定标签获取它,我也尝试过,但它不适用于标签 query_posts('tag=my-guide');-

    <?php query_posts('tag=my-guide'); 
  while (have_posts()) : the_post();  
?>  
<div class="breaking">  
    <img src="<?php echo get_post_meta($post->ID, 'thumbnail',true) ?>" alt="Post Image" class="postimg" />  
    <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>  
    <p class="datetime"><?php the_time('l, F j, Y G:i'); ?></p>  
    <?php the_content('Continue...'); ?>  
    <div class="postmeta">  
        <p><?php the_category(', '); ?> - <a href="<?php the_permalink() ?>#commenting" title="View Comments">  
    <span class="comm"><?php comments_number('0 Comments','1 Comment','% Comments'); ?></span></a></p>  
    </div><!--/postmeta-->  
</div><!--/breaking-->  
<?php endwhile; ?>  

这个来源-> http://net.tutsplus.com/tutorials/wordpress/build-a-featured-posts-section-for-wordpress/

4

1 回答 1

0

我自己修复了代码 -

第二个代码块的问题在于,没有为此投入任何价值 -$post->ID

所以这个方法调用在代码中没有任何好处 -

<?php echo get_post_meta($post->ID, 'thumbnail',true) ?>

要解决此问题,只需调用,<?php the_post_thumbnail(); ?>而不是<img src="<?php echo get_post_meta($post->ID, 'thumbnail',true) ?>" alt="Post Image" class="postimg" />

所以这是general特定标签帖子显示的工作代码 -

<?php query_posts('tag=your-tag'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="thumbnail">  
        <?php the_post_thumbnail(); ?>
        <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>  
        <p class="datetime"><?php the_time('l, F j, Y G:i'); ?></p>  
        <?php the_content('Continue...'); ?>  
        <div class="postmeta">  
            <p><?php the_category(', '); ?> - <a href="<?php the_permalink() ?>#commenting" title="View Comments">  
        <span class="comm"><?php comments_number('0 Comments','1 Comment','% Comments'); ?></span></a></p>  
        </div>
    </div>  
<?php endwhile; endif; ?>
于 2013-01-29T12:25:26.613 回答