我想在wordpress中重新安排我最近的帖子,这样它们就会升序/降序。
下面是我的代码:
<ul>
<?php query_posts('cat=3,4,5&posts_per_page=5&order=ASC'); foreach ($post as $post) ?>
<li>
<span class="date"><?php the_time('M j') ?></span>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>每个帖子都是从不同的类别中提取出来的。查看网站here
发布于 2010-05-01 02:59:53
为什么不使用标准的query_posts
<?php
//The Query
query_posts('cat=3,4,5&posts_per_page=5&order=ASC');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;
?>这段代码应该可以工作,如果您使用get_posts而不是query_posts的另一个原因,您的问题很可能是您的参数列表-在我看来,您将需要更改
get_posts('cat=3,4,5,numberposts=5&order=DESC&orderby=date')至
get_posts('cat=3,4,5&numberposts=5&order=DESC&orderby=date')因为&被用来分隔参数。
发布于 2010-05-01 02:46:20
也可以尝试使用"orderby“...
请参阅:http://codex.wordpress.org/Template_Tags/get_posts
发布于 2010-05-01 03:36:09
我会将类别3、4、5放在父类别下。然后,您可以只拉入单个类别(父类别)。例如,如果您的新父类别为17,您将执行以下操作:
<?php query_posts('cat=17&numberposts=5&order=DESC&orderby=date'); foreach ($post as $post) ?>这将显示17类中的帖子和17类的任何子类。那么排序应该按照你所期望的那样进行。
https://stackoverflow.com/questions/2746821
复制相似问题