根据父分类调用wordpress分类列表模板

以分类ID为4的父分类作为例子 if (cat_is_ancestor_of(4, $cat)) { get_template_part('category-4-child'); } else { get_template_part('category'); } 将代码放到要调用的分类模板中即可

wordpress子分类使用父分类模板

子分类使用父分类模板 function f_category_template($template){ $category = get_queried_object(); if($category->parent !='0'){ while($category->parent !='0'){ $category = get_category($category->parent); } } $templates = array(); if ( $category ) { $templates[] = "category-…

wordpress父分类和归档页调用子分类名称和链接

category和archives调用下级子分类的名称和链接 <?php if ( is_category() ) { $this_category=g et_category( $cat ); } ?> <?php if ( $this_category->category_parent ) $this_category = wp_list_categories( 'orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_…

wordpress显示相同父分类目录下的所有子分类目录

在制作wordpress列表模板的时候,经常会用到调用同录分类目录的情况,这段代码完美解决了这一问题。 <?php $cat = get_queried_object(); $list = wp_list_categories( [ 'taxonomy' => $cat->taxonomy, 'child_of' => $cat->parent, 'title_li' => '', 'echo' => 0, ] ); if ( $list ) { …

wordpress子分类调用父分类名称和链接

专为导航而生,在wordpress模板制作过程中常常会在做breadcrumbs导航时会用到,子分类调用父分类的名称和链接,下面这段简洁的代码,可以完美解决这个问题。 <?php echo get_category_parents( $cat, true, ' &raquo; ' ); ?> 下面这种方法也可以,不过代码不够简洁。 <?php if ( is_category() ) …