2010-08-15 44 views
0

我在Wordpress中有一個頁面,僅顯示具有「報紙」類別的帖子。現在,這些帖子按降序排列(我認爲,如果這是默認值),則最新的帖子位於頂部。在Wordpress中使用PHP在頂部顯示帶有「精選」標籤的帖子

這是我的代碼:

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

我在想,如果有可能,以顯示與在頂部有一個「特色」標籤的帖子,而所有其他職位沒有一個特色標籤之後。

謝謝! Amit

回答

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

就像我說的,這不是做事情最徹底的方法,但它的作品。如果你有其他建議,我全部耳朵:)

謝謝! Amit

相關問題