簡體   English   中英

WordPress的類別>帖子排序

[英]Wordpress Category > Posts Orderby

我試圖按標題對帖子排序,但是我無法使其正常工作,我試圖將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 } ?>

真的謝謝你能幫忙!

我發現傳遞一個關聯數組會使它更容易消化。 嘗試這個:

// Refactored query arguments
query_posts(array(
  'cat' => $categories_item->term_id,
  'posts_per_page' => 9999,
  'order' => 'ASC', //order ascending
  'orderby' => 'title' //order by title
));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM