0

我正在尝试按标题对帖子进行排序,但我无法让它工作,我试图将 orderby 插入到 query_posts 但我认为当你可以添加多个设置时,我不明白你如何编写 query_posts 值的逻辑&。

这是我的代码。

<?php
$cat_id = get_query_var('cat');
$catlist = get_categories('hide_empty=0&child_of=' . $cat_id);
$cat_child = get_field('frontend_name' , 'category_'  . get_query_var('cat' ));

foreach($catlist as $categories_item) {
    echo "<ol>";
    echo '<h3><a href="' . get_category_link( $categories_item->term_id ) . '" ' . '>' . $categories_item->description .'</a> </h3> ';
    query_posts("cat=" . $categories_item->term_id . "&post_per_page=9999");

if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink();?>">
      <?php the_title(); ?>
   </a></li>
<?php endwhile; endif; ?>
<?php echo "</ol>"; ?>
<?php } ?>

如果您能提供帮助,真的很感谢!

4

1 回答 1

0

我发现传递一个关联数组使它更容易消化。试试这个:

// Refactored query arguments
query_posts(array(
  'cat' => $categories_item->term_id,
  'posts_per_page' => 9999,
  'order' => 'ASC', //order ascending
  'orderby' => 'title' //order by title
));
于 2013-03-06T00:54:12.540 回答