显示当前文章分类和父分类的链接

当需要显示文章的父分类和当前分类链接时,我们可以使用这段代码:

  1.  = get_the_category();
  2.  \'<ul>\’;
  3.  \'<li> Parent Category: \’;
  4. (    ){
  5.      (->parent != 0){
  6.            = get_term( ->parent );
  7.            \'<a href=>\’ . esc_html(->name) . \’ </a>\’;
  8.           ;
  9.      }
  10. }
  11.  \'</li>\’;
  12.  \'<li>Subcategory: \’;
  13. (    ){
  14.      (->parent != 0){
  15.            \'<a href=>\’ . esc_html(->name) . \’ </a>\’;
  16.      }
  17. }
  18.  \'</li></ul>\’;

代码原自:http://wordpress.stackexchange.com/questions/247011/access-current-post-parent-and-sub-category

    © 版权声明
    THE END
    喜欢就支持一下吧
    点赞0 分享
    评论 抢沙发

    请登录后发表评论

      暂无评论内容