Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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 - Fatal编程技术网

Php Wordpress为子类别和文章使用自定义模板

Php Wordpress为子类别和文章使用自定义模板,php,wordpress,Php,Wordpress,有一个大的通用类别目录($category->cat_ID=2)。它包含一些子类别,如系列1,系列2等。每个子类别都包含一些子类别,如Type1,Type2,等等。每个子类别都包含一些产品(typepost)。 我不需要显示普通类别目录及其子类别,但我需要在单独页面上显示其产品的子类别。 如何为categoryCatalog及其子类别设置404.php模板,以及为每个子类别(带产品列表)和每个产品设置自定义模板 我在下面找到了代码(functions.phpfile) 但我不知道如何根据我的需要

有一个大的通用类别
目录
$category->cat_ID=2
)。它包含一些子类别,如
系列1
系列2
等。每个子类别都包含一些子类别,如
Type1
Type2
,等等。每个子类别都包含一些产品(type
post
)。
我不需要显示普通类别
目录及其子类别,但我需要在单独页面上显示其产品的子类别。
如何为category
Catalog
及其子类别设置
404.php
模板,以及为每个子类别(带产品列表)和每个产品设置自定义模板

我在下面找到了代码(
functions.php
file)

但我不知道如何根据我的需要定制它

UPD.我已经编写了下面的代码

function catalog_template() {    
// Get the category id from global query variables
$cat = get_query_var('cat');

if(!empty($cat)) {    
    $catalog_id = get_cat_ID('Catalog');

    $catalog_child_cats = array();

        foreach(get_all_category_ids() as $child_cat)
        {
            if(get_category($child_cat)->parent==$catalog_id)
            {
                $catalog_child_cats[]=$child_cat;
            }
        }

    // Get the detailed category object
    $category = get_category($cat);
    $cat_parent_id = $category->cat_ID;

    // Check if it is sub-category and having a parent, also check if the template file exists
    if( (in_array($cat_parent_id, $catalog_child_cats)) && (file_exists(TEMPLATEPATH . '/catalog.php')) ) { 

        // Include the template for sub-sub-catgeory
        include(TEMPLATEPATH . '/catalog.php');
        exit;
    }
    return;
}
return;

}
add_action('template_redirect', 'catalog_template');
但它也为
子类别
使用
catalog\u模板。如何为普通类别
Catalog
及其子类别设置
404.php

UPD2我在代码中发现了一个错误,需要更正

// Get the detailed category object
    $category = get_category($cat);
    $cat_parent_id = $category->category_parent;

我建议不要使用404,因为这意味着一些不同的、具体的东西;内容不存在或不可用,内容不是此分类法的子项

但是,如果你想。。。。。只需从404.php中复制代码,并将其嵌套在查询category+1级别的条件语句中。大概是这样的:

如果(是_类别(“目录”)){ $this_category=get_queryed_object(); 如果(0!=$this_category->parent){ //来自404.php的代码 }}


我建议不要使用404,因为这意味着一些不同的、具体的东西;内容不存在或不可用,内容不是此分类法的子项

但是,如果你想。。。。。只需从404.php中复制代码,并将其嵌套在查询category+1级别的条件语句中。大概是这样的:

如果(是_类别(“目录”)){ $this_category=get_queryed_object(); 如果(0!=$this_category->parent){ //来自404.php的代码 }}

// Get the detailed category object
    $category = get_category($cat);
    $cat_parent_id = $category->category_parent;