使用WP类别永久链接插件与Yoast Breadcrumb

时间:2015-04-15 22:16:45

标签: php wordpress plugins

我正在使用一个名为WP Category Permalink的wordpress插件,如果有一些与帖子关联的类别,您可以选择一个特定的类别作为帖子的永久链接。

该插件效果很好,并且显示了我想要的父类别我想要的网址,但是我也使用了Yoast SEO插件中提供的面包屑工具,我喜欢面包屑遵循由WP Category Permalink插件确定的相同永久链接结构。 breadcrumb只使用父类别的默认显示,并按字母顺序显示第一个。

在查看类别永久链接插件的支持部分后,似乎有人有同样的想法,并提供以下代码,他已使用另一个breadcrumb插件:

add_filter("get_the_categories","chr_primary_category");
function chr_primary_category($cats){
    global $post;
    $chr_catmeta = get_post_meta($post->ID,"_category_permalink",true);
    if($chr_catmeta == "") { 
        return $cats; // save our energy if there's no primary category set
    }
    $specialcat = "";
    foreach($cats as $key=>$cat){
        if($cat->term_id == $chr_catmeta){
            $specialcat = $cat;
            unset($cats[$key]);
        }
    }
    if($specialcat != ""){
        $cats = array_merge(array($specialcat),$cats); // merge it all back together, with our special category first
    }
    return $cats;
}

但我不知道如何利用它,所以希望有人有一些想法或尝试过类似的东西。我甚至无法回显chr_primary_category函数数组而不会抛出错误。

由于

0 个答案:

没有答案