admin管理员组文章数量:1122832
I am building a quotes website and i have 2 main categories like Topic & Authors
Every quote will have Author name and topic name and those are sub categories of Topic & Author.
AND my question is
i want to display only Author categories that is a sub category of a Authors category please help me...
Topic
- Love
- Life
- Friends etc
Authors
- Author1
- Author2
- Author3
I am building a quotes website and i have 2 main categories like Topic & Authors
Every quote will have Author name and topic name and those are sub categories of Topic & Author.
AND my question is
i want to display only Author categories that is a sub category of a Authors category please help me...
Topic
- Love
- Life
- Friends etc
Authors
- Author1
- Author2
- Author3
2 Answers
Reset to default 0It will give you the same structure as shown above:
wp_list_categories(array('hide_empty'=>0, 'hierarchical' => true, 'include' => array('12','12')));
<?php
// names / IDs of parents
$parents = array(
'par2' => 76
);
// get post categories
$categories = get_the_terms( $post->ID, 'category' );
// output top level cats and their children
foreach( $parents as $parent_name => $parent_id ):
// output parent name and link
//echo '<a href="' . get_term_link( $parent_id, 'category' ) . '">' . $parent_name . '</a>: ';
// initialize array to hold child links
$links = array();
foreach( $categories as $category ):
if( $parent_id == $category->parent ):
// put link in array
$links[] = '<li><a href="' . get_term_link( $category ) . '">' . $category->name . '</a></li>';
endif;
endforeach;
// join and output links with separator
echo join($links );
endforeach;
?>
This is the answer i am looking for thanks for replys
本文标签: List only child categories a post is inof a specific parent category in wordpress
版权声明:本文标题:List only child categories a post is in, of a specific parent category in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736282808a1926761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论