我想在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
答案 0 :(得分:3)
为什么不使用标准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')
因为&
用于分隔参数。
答案 1 :(得分:1)
尝试使用“orderby”......
答案 2 :(得分:0)
我会将类别3,4,5放在父类别下。然后你可以拉入单一类别(父类别)。例如,如果你是新的父类别是17,你会这样做:
<?php query_posts('cat=17&numberposts=5&order=DESC&orderby=date'); foreach ($post as $post) ?>
这将显示第17类中的帖子和第17类儿童中的任何一个。然后按照您的预期进行排序。