Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将WP Category Permalink插件与Yoast面包屑一起使用_Php_Wordpress_Plugins - Fatal编程技术网

Php 将WP Category Permalink插件与Yoast面包屑一起使用

Php 将WP Category Permalink插件与Yoast面包屑一起使用,php,wordpress,plugins,Php,Wordpress,Plugins,我正在使用一个名为wordpress的插件,它允许你选择一个特定的类别作为一篇文章的永久链接,如果有许多类别与一篇文章相关 该插件工作得很好,显示了我所选择的父类别的url,但是我也在使用Yoast SEO插件中提供的面包屑功能,我希望面包屑遵循插件确定的相同永久链接结构。面包屑只使用父类别的默认显示,并按字母顺序显示第一个类别 在查看Permalink插件类别的支持部分后,似乎有人有相同的想法,并提供了以下代码,他已将这些代码用于另一个面包屑插件: add_filter("get_the_ca

我正在使用一个名为wordpress的插件,它允许你选择一个特定的类别作为一篇文章的永久链接,如果有许多类别与一篇文章相关

该插件工作得很好,显示了我所选择的父类别的url,但是我也在使用Yoast SEO插件中提供的面包屑功能,我希望面包屑遵循插件确定的相同永久链接结构。面包屑只使用父类别的默认显示,并按字母顺序显示第一个类别

在查看Permalink插件类别的支持部分后,似乎有人有相同的想法,并提供了以下代码,他已将这些代码用于另一个面包屑插件:

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函数数组


谢谢

您得到了什么错误?
警告:为localhost等中的foreach()提供的参数无效。
可能在同一操作上有另一个筛选器。如果您有一个调试器,您可以在输入时中断代码,并为$cats设置一个监视,以查看它是否确实是一个数组。