我在WordPress网站的导航列表中订购一些帖子时遇到问题。 这是我(严重缩进)的代码:
<ul class="tree lvl-0">
<?php
$args = array('child_of' => 6);
$categories = get_categories( $args );
foreach($categories as $category) {
echo '<li class="collapsed"><a href="' . get_category_link( $category->term_id ) . '"' . $category->name . '" ' . '>' . $category->name.'</a>';
$cat_id= $category->term_id;
wp_reset_query();
$args = array(
'cat' => $cat_id,
'posts_per_page' => 20,
'order' => 'ASC',
'orderby' => 'title'
);
query_posts($args);
// start the wordpress loop!
?>
<ul class="lvl-1">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>
</li>
<?php wp_reset_query(); } ?>
</ul>
有问题的部分是
$args = array(
'cat' => $cat_id,
'posts_per_page' => 20,
'order' => 'ASC',
'orderby' => 'title'
);
query_posts($args);
我不太确定它们的顺序是什么,可能是日期。此外,当我按"名称"或其他任何内容排序时,它可以工作。:(
提前感谢您的任何帮助
问题是$args,这样做:
$args = array(
'cat' => $cat_id,
'posts_per_page' => 20,
'orderby' => array( 'title' => 'ASC' )
);
您还可以按多个参数排序,例如:
$args = array(
'cat' => $cat_id,
'posts_per_page' => 20,
'orderby' => array( 'menu_order' => 'ASC', 'title' => 'ASC', 'post_date' => 'DESC' ),
);
参见 Hobo 对问题的评论 ^
我的客户也在使用 qTranslate,这是问题的确切原因。