我在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;?>

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

谢谢!阿米特

有帮助吗?

解决方案

好吧,这就是我暂时做的。我不依赖特色 标签, ,而是在特色新闻类别上。这并不是我想要它的方式,但这将暂时做到:

<?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;?>

就像我说的那样,这不是做事的最干净的方式,但它可以起作用。如果您还有其他建议,我全都是耳朵:)

谢谢!阿米特

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top