使Wordpress子类别使用类别模板 [英] Make Wordpress subcategories use Category Template

查看:60
本文介绍了使Wordpress子类别使用类别模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类别模板:category-projects.php

I've got a category template: category-projects.php

该类别有子类别,但他们参考模板category.php以获得说明父类别的

This category has subcategories, but they're refering to the template category.php for instructions instead of the parent category. How do I make subcategories refer to parent category templates in the cascading order of template references?

*注意,我在说的是类别级别的URL,而不是帖子。

*Note, I'm talking about category level urls, not posts.

推荐答案

一种方法是插入 functions.php 文件中的Action_Reference#Template_Actions rel = noreferrer> template_redirect 操作:

One way to do this is to hook into the template_redirect action in your functions.php file:

function myTemplateSelect() {
    if (is_category() && !is_feed()) {
        if (is_category(get_cat_id('projects')) || cat_is_ancestor_of(get_cat_id('projects'), get_query_var('cat'))) {
            load_template(TEMPLATEPATH . '/category-projects.php');
            exit;
        }
    }
}

add_action('template_redirect', 'myTemplateSelect');

这篇关于使Wordpress子类别使用类别模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆