如何按类别对Wordpress搜索结果进行分组

时间:2018-08-19 20:46:40

标签: wordpress search

我使用的一个主题显示了按类别分组的搜索结果...不幸的是,如果我将该代码复制到我的新主题中,它将无法正常工作...有人可以看看并告诉我如何解决它?

<?php
$exclude_cats = array(1,3,4,262,2117,5876,6242,10809,);
     foreach($posts as $post) :
     $category = get_the_category();
        if(!isset ($category[0]->cat_ID, $exclude_cats)) {
            $cats[$category[0]->cat_ID] = $category[0]->cat_name;
            $cat_posts[$category[0]->cat_ID] = $post;
        }
     endforeach;

     uasort($cats, strcasecmp);
     $cats = array_flip($cats);?>

<?php
    foreach($posts as $post) :
        the_post();
        $category = get_the_category();
        if($current_cat == $category[0]->cat_ID) : // if post is in correct category ?>``

提前谢谢!

0 个答案:

没有答案