2013-05-07 59 views

回答

0

UPDATE:

这是我的理解你的问题:)

现在我假设你想要的是用于分类Widget的仅显示父(主)类别的第二次尝试。

如果是这样,你可以使用此代码:

function include_widget_categories($args) 
{ 

    $cats_id=""; 
    $parent_args = array(
    'orderby' => 'name', 
    'parent' => 0 
    ); 
    $categories = get_categories($parent_args); 

    foreach ($categories as $category) 
     $cats_id.=$category->cat_ID.","; 

    $cats_id=substr($cats_id,0,-1); 

    $args["include"] = $cats_id;// The IDs of the including categories 
    return $args; 
} 
    add_filter("widget_categories_args","include_widget_categories"); 

添加在functions.php中上面的代码。

+0

我只想显示主要类别。 例如: 游戏 - 普通类 体育 - 儿童类别 我现在显示一个特别好宝贝,我想看到的,而不仅仅是游戏和运动 – user2359454 2013-05-08 15:06:31

+0

我更新了答案。我希望这是你需要的。 – user850010 2013-05-08 18:22:17

+0

它的工作原理,谢谢 – user2359454 2013-05-08 19:08:12

相关问题