Php Wordpress如果父项{}如果子项{}
我会说我是php的noob,但我觉得我至少有点理解它 好的,我正在wordpress中创建一个主题,但是category.php有问题。当wordpress在category.php中读取时,我需要一个类似于以下内容的if语句Php Wordpress如果父项{}如果子项{},php,wordpress,parent,categories,Php,Wordpress,Parent,Categories,我会说我是php的noob,但我觉得我至少有点理解它 好的,我正在wordpress中创建一个主题,但是category.php有问题。当wordpress在category.php中读取时,我需要一个类似于以下内容的if语句 <?php $cate = get_category($cat); if ($cate->category_parent == 1) { require_once ( get_template_directory() . '/category-p
<?php
$cate = get_category($cat);
if ($cate->category_parent == 1) {
require_once ( get_template_directory() . '/category-parent.php' ); }
else if($cate->category_parent == 0) {
require_once ( get_template_directory() . '/category-child.php' ) }
endif; ?>
是的,所以如果家长使用这个模板,如果孩子使用这个模板,我的意思是像page.php模板
谢谢 .'/category-parent.php;}=>。'/类别parent.php';}。孩子也一样
$sep = '»';
$parents = get_category_parents( $cat, TRUE, $sep );
$parents = explode( $sep, trim( $parents, $sep ) );
if( 1 === count( $parents ) ) {
/* No category parents. */
require_once ( get_template_directory() . '/category-parent.php' );
}
else {
/* One or more parent categories. */
require_once ( get_template_directory() . '/category-child.php' );
}