根据:http://codex.wordpress.org/Function_Reference/query_posts
要显示类别中的所有帖子,请执行以下操作:
query_posts( array ( \'category_name\' => \'The Category Name\', \'posts_per_page\' => -1 ) );
很好,但如果我想显示帖子按ID描述订购
有人知道怎么做吗?
根据:http://codex.wordpress.org/Function_Reference/query_posts
要显示类别中的所有帖子,请执行以下操作:
query_posts( array ( \'category_name\' => \'The Category Name\', \'posts_per_page\' => -1 ) );
很好,但如果我想显示帖子按ID描述订购
有人知道怎么做吗?
您需要将其用于参数orderby
和order
<?php query_posts( array( \'category_name\' => \'my_category_slug\', \'orderby\' => \'ID\', \'order\' => \'DESC\', \'posts_per_page\' => -1 ) ); ?>
param order可以通过DESC列出,param orderby sort by idf可以用于您的示例:
query_posts(
array ( \'category_name\' => \'The Category Name\',
\'posts_per_page\' => -1,
\'orderby\' => \'ID\',
\'order\' => \'DESC\'
)
);
Order只能与ASC或DESC一起使用,orderby可以使用表POST的所有字段。我正在一个自定义插件上运行一个查询,以显示所有类别,并将它们放入下拉列表(所选部分位于循环之外),如下所示:<?php $ember_categories = get_categories(); foreach($ember_categories as $ember_category) { echo \'<option value=\"\' . $ember_category->cat_ID . \'\">\' . $ember_category-&