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

查看:33
本文介绍了使 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?

*注意,我说的是类别级别的网址,而不是帖子.

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

推荐答案

一种方法是挂接到 functions.php 文件中的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天全站免登陆