【问题标题】:order results by category, wordpress按类别排序结果,wordpress
【发布时间】:2012-07-07 14:20:40
【问题描述】:

我有一个名为“功能”的类别页面,这很好,但是功能类别中的帖子也属于某种电影类型,这就是我想在实际功能类别模板上对帖子进行排序的内容.

例如

功能猫模板引入了所有功能帖子。

那么我想要做的是按它所属的任何类型以 alpha 顺序显示

features
      action
         post
         post
         post
      comedy
         post
         post
       sci-fi
         post
         post

等等

这就是我目前所拥有的(猫的数量与流派有关 = action=10 等)

query_posts('cat=10,11,12,13,14,15,16,17,18&orderby=title&order=DESC' );
while (have_posts()) : the_post(); 

如何按类型列出所有帖子(将它们分组)?当我在这里使用标题时,我猜它正在使用帖子标题。

如果我把它放在帖子循环中,那就玩吧

foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(4, $childcat)) {
        echo $childcat->cat_name;

    }
}

这会在循环中返回每个帖子的实际流派猫,但我不知道如何将它粘在一起,所以我可以按流派组说明帖子的顺序,我希望我能做到这一点查询帖子?

我们将不胜感激任何正确方向的帮助。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我会考虑首先查询您的子类别,然后遍历您的子类别,查询每个子类别的帖子。像这样:

    $categories =  get_categories( array ( 'child_of' => 10, 'orderby' => 'name' ) );
    foreach( $categories as $category ){
        // query_posts for category by $category->term_id
        // Display posts for this category
    }
    

    这对你想做的事情有用吗?

    【讨论】:

      猜你喜欢
      • 2018-05-18
      • 2016-07-29
      • 2013-10-03
      • 2015-02-14
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多