2010-02-21 254 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/

相关问题