当需要显示文章的父分类和当前分类链接时,我们可以使用这段代码:
- = get_the_category();
- \'<ul>\’;
- \'<li> Parent Category: \’;
- ( ){
- (->parent != 0){
- = get_term( ->parent );
- \'<a href=>\’ . esc_html(->name) . \’ </a>\’;
- ;
- }
- }
- \'</li>\’;
- \'<li>Subcategory: \’;
- ( ){
- (->parent != 0){
- \'<a href=>\’ . esc_html(->name) . \’ </a>\’;
- }
- }
- \'</li></ul>\’;
代码原自:http://wordpress.stackexchange.com/questions/247011/access-current-post-parent-and-sub-category
暂无评论内容