我想列出我最近发表的10篇文章,但仅限于某些类别——任何人都可以告诉我怎么做?
谢谢
我想列出我最近发表的10篇文章,但仅限于某些类别——任何人都可以告诉我怎么做?
谢谢
只需将此添加到循环上方
$args = array(
\'posts_per_page\' => 10,
\'category__in\' => array( 2, 6 ), //change and add the category ids here
\'orderby\' => \'date\',
\'order\' => \'ASC\')
query_posts($args);
您可以阅读有关query\\u posts参数的更多信息http://codex.wordpress.org/Function_Reference/WP_Query#Parameters$args = array(
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array(\'category1\',\'category2\') ////change and add the category slugs here
)
)
\'posts_per_page\' => 10,
\'orderby\' => \'date\',
\'order\' => \'ASC\')
query_posts($args);
最简单的方法是在循环开始之前在查询中使用类别名称。
<?php query_posts($query_string . \'&category_name=\'Your Category, Another Category\'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
我还没有测试过,但应该可以。也请查看http://codex.wordpress.org/Function_Reference/query_posts