使用Wordpress中的PHP在顶部显示带有“精选”标签的帖子

时间:2010-08-15 09:24:35

标签: php wordpress posts

我在Wordpress中有一个页面,只显示“报纸”类别的帖子。现在,帖子按降序排列(我认为,如果这是默认值),最新的位于顶部。

这是我的代码:

<?php $my_query = new WP_Query('category_name=newspaper&posts_per_page=-1'); ?>

<?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
<!--<h3><?php the_title(); ?></h3>-->
<?php the_content('Read the rest of this entry &raquo;'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>

我想知道是否可以在顶部显示带有“精选”标签的帖子,而之后所有其他帖子都没有精选标签。

谢谢! 阿米特

1 个答案:

答案 0 :(得分:0)

好的,这是我暂时做的。我不依赖于精选的标签,而是依赖于特色报纸类别。这不是我想要的样子,但现在这样做了:

<?php $my_query = new WP_Query('category_name=newspaper&posts_per_page=-1'); ?>
<?php $my_featured = new WP_Query('category_name=featured-newspaper&posts_per_page=-1'); ?>

<!-- featured posts -->
<?php if (have_posts()) : while ($my_featured->have_posts()) : $my_featured->the_post(); ?>
<div class="post">
    <!--<h3><?php the_title(); ?></h3>-->
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <div class="clear"></div>
</div>
<?php endwhile; endif;?>
<!-- /end featured -->


<?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
    <!--<h3><?php the_title(); ?></h3>-->
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <div class="clear"></div>
</div>
<?php endwhile; endif;?>

就像我说的那样,这不是最干净的做事方式,但它确实有效。如果您有其他建议,我会全力以赴:)

谢谢! 阿米特