2010-02-21 250 views
0

我有3箱,我有我的主頁的底部,我想在他們每個人中顯示一個WordPress的帖子。WordPress的:顯示類別帖子

這些帖子中的每一個都屬於special1,special2,special3類別,我該怎麼做?

我已經試過

<div class="special_box"> 
     <?php query_posts('tag=special3');?> 
    </div> 

但這不起作用

任何想法?我想這一點,但它取代了所有我的其他內容只有一職,這是不是我想要

這是WordPress的外循環:

<?php 

$ special1 = query_posts('CATEGORY_NAME = special1 「); >

這裏面?

<div class="special_box"> 
     <?php echo $special1 ;?> 
    </div> 

回答

2

這個新的查詢將顯示來自一個類別最新帖子,並且可以多次使用的頁面/後(啓用PHP excecution)和內標準WP循環:

<?php $my_query = new WP_Query('category_name=special1&showposts=1'); ?> 
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?> 
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> 
<?php the_title(); ?></a><br /><?php the_content(); ?><?php endwhile; ?> 

Function Reference/WP Query « WordPress Codex

+0

謝謝,完美的作品:) – user195257 2010-02-21 14:43:44

0

另一種方法是使用類別數量(無所謂)。但是這個代碼更容易:

<?php wp_reset_query(); ?> 

<?php query_posts('cat=5'); ?> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
    <?php the_content(); ?> 
<?php endwhile; endif; ?> 

http://snippetcentral.com/query-posts-category/

相關問題