按类别排序结果,wordpress


order results by category, wordpress

我有一个名为"features"的类别页面,这一切都很好,但features类别中的帖子也属于某种类型的电影,这就是我想要在实际的features分类模板上排序帖子的原因。

例如

featurescat模板引入所有features帖子。

然后我想做的是按字母顺序显示它也属于的任何类型

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

等等。

这就是我现在拥有的(猫的数量与流派有关=动作=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;
    }
}

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

如果能在正确的方向上提供任何帮助,我们将不胜感激。

我会考虑首先查询子类别,然后循环查询子类别中的每个帖子。像这样:

$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
}

这对你想要做的事情有效吗?