Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress如果父项{}如果子项{}_Php_Wordpress_Parent_Categories - Fatal编程技术网

Php Wordpress如果父项{}如果子项{}

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的noob,但我觉得我至少有点理解它

好的,我正在wordpress中创建一个主题,但是category.php有问题。当wordpress在category.php中读取时,我需要一个类似于以下内容的if语句

<?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' );
}