Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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 在Wordpress的作者存档中显示作者使用的类别_Php_Wordpress - Fatal编程技术网

Php 在Wordpress的作者存档中显示作者使用的类别

Php 在Wordpress的作者存档中显示作者使用的类别,php,wordpress,Php,Wordpress,我想显示仅由给定作者使用的所有类别,并在作者存档中显示具有层次结构的父级和子级 示例: <ul> <li><a href="http://example.com/?cat=56">A</a> <ul> <li><a href="http://example.com/?cat=57">A1</a></li> <li><a href="

我想显示仅由给定作者使用的所有类别,并在作者存档中显示具有层次结构的父级和子级

示例:

<ul>
<li><a href="http://example.com/?cat=56">A</a>
    <ul>
        <li><a href="http://example.com/?cat=57">A1</a></li>
        <li><a href="http://example.com/?cat=58">A2</a></li>
    </ul>
</li>
<li><a href="http://example.com/?cat=3">B</a></li>
<li><a href="http://example.com/?cat=4">C</a></li>
<li><a href="http://example.com/?cat=5">D is not displayed because author didn't post in this category</a></li>
</ul>
  • A1是A的孩子
  • A2是A的孩子
  • 作者在A1中发布了1篇帖子
  • 作者在A2中发布了1篇帖子
  • 作者用C和A1发表了1篇文章(同一篇文章)
  • 作者在B中发表了1篇文章
需要结果:

<ul>
<li><a href="http://example.com/?cat=56">A</a>
    <ul>
        <li><a href="http://example.com/?cat=57">A1</a></li>
        <li><a href="http://example.com/?cat=58">A2</a></li>
    </ul>
</li>
<li><a href="http://example.com/?cat=3">B</a></li>
<li><a href="http://example.com/?cat=4">C</a></li>
<li><a href="http://example.com/?cat=5">D is not displayed because author didn't post in this category</a></li>
</ul>
$cat_array=array();
$args=数组(
'author'=>获取作者元('id'),
“展示帖子”=>-1,
“来电者获取帖子”=>1
);
$author\u posts=get\u posts($args);
如果($author\u posts){
foreach($author\u post为$author\u post){
foreach(获取类别($author\u post->ID)作为$category){
$cat\u数组[$category->term\u id]=$category->term\u id;
}
}
}
$cat_id=内爆(“,”,$cat_数组);
echo$output=strtr(wp_-list_-categories('include='.$cat_-id.&title_-li=&style=none&echo=0')、数组('
'=>'/'));