wordpress获取分类的顶级分类
wordpress子分类获取父分类
方法一
方法二
wordpress获取分类的顶级父类
第一个函数(get_term_top_most_parent)接受一个分类ID和分类 ??,并返回分类的顶级父类(或本身);
第二功能(hey_top_parents)工作在循环中,以及,给定的分类法,返回后的分类顶层祖先。
161718192021222324252627282930313233343536373839404142// determine the topmost parent of a termfunction get_term_top_most_parent($term_id, $taxonomy){// start from the current term$parent= get_term_by( 'id', $term_id, $taxonomy);// climb up the hierarchy until we reach a term with parent = '0'while ($parent->parent != '0'){$term_id = $parent->parent;$parent= get_term_by( 'id', $term_id, $taxonomy);}return $parent;}// so once you have this function you can just loop over the results returned by wp_get_object_termsfunction hey_top_parents($taxonomy, $results = 1) {// get terms for current post$terms = wp_get_object_terms( get_the_ID(), $taxonomy );// set vars$top_parent_terms = array();foreach ( $terms as $term ) {//get top level parent$top_parent = get_term_top_most_parent( $term->term_id, $taxonomy );//check if you have it in your array to only add it onceif ( !in_array( $top_parent, $top_parent_terms ) ) {$top_parent_terms[] = $top_parent;}}// build output (the HTML is up to you)foreach ( $top_parent_terms as $term ) {$r = '<ul>';$r .= '<li><a href="'.%20get_term_link(%20$term->slug,%20$taxonomy%20)%20.%20'">' . $term->name . '</a></li>';}$r .= '</ul>';// return the resultsreturn $r;}
DedeCMS 核心类TypeLink.class.p
织梦cms系统TAG标签和分页伪静态
织梦cms列表页/内容页调用当前文
dedecms会员中心常用信息输出
dede搜索结果页支持article、sql
织梦cms批量取消审核文档的实现
织梦dedecms wap手机门户站点首
织梦dedecms在模板页面中实现会
织梦导航不显示外部链接栏目,修
织梦dedecms使用Mysql8.0无法登