WordPress 获取父分类 ID

知更鸟 WordPress 开发评论159阅读模式

有时需要调用当前分类父分类 的ID,可以用:

$thiscat   =  get_query_var( 'cat' ); // 当前分类id
$catobject = get_category( $thiscat, false ); // 通过当前分类的id获取父分类
$parentcat = $catobject->category_parent; // 父分类类的id
echo $parentcat;

 文章源自知更鸟-https://zmingcx.com/wordpress-get-parent-category-id.html

文章源自知更鸟-https://zmingcx.com/wordpress-get-parent-category-id.html文章源自知更鸟-https://zmingcx.com/wordpress-get-parent-category-id.html
weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
评论  0  访客  0
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定