傻大憨

wordpress根据文章分类自动调用指定页面模板

通过wordpress分类目录的别名来调用指定的single模板

 add_action('template_include', 'load_single_template');
 function load_single_template($template) {
 $new_template = '';
 if( is_single() ) {
 global $post;
 // 新闻
 if( has_term('news', 'category', $post) ) {
 $new_template = locate_template(array('single-newsinfo.php' ));
        }
 // 团队
 if( has_term('team', 'category', $post) ) {
 $new_template = locate_template(array('single-team.php' ));
        }
 // 案例
 if( has_term('case', 'category', $post) ) {
 $new_template = locate_template(array('single-case.php' ));
        }
 // 产品
 if( has_term('product', 'category', $post) ) {
 $new_template = locate_template(array('single-product.php' ));
        }
     }
 return ('' != $new_template) ? $new_template : $template;
 }

把上面的代码,添加到functions.php文件中即可。

Published
Categorized as 建站知识 Tagged ,

By 傻大憨

shadahan.com是一个关注跨境电商、创业话题的网站。

wordpress子分类使用父分类模板

wordpress子分类继承使用父分类模板

山东专业的外贸建站公司

鲁大齐Ludaqi.com山东专业的外贸建站公司是一家专注于为企业提供高质量外贸网站建设服务的公司。

建跨境电商独立站 定制比买模板更靠谱

在跨境电商独立站的建设过程中,选择定制开发还是购买模板是一个重要的决策。我们可以详细分析这两种方式的优缺点。

企业官网在海外品牌推广中的重要工具

企业官网在海外品牌推广中不仅是品牌形象的展示窗口,更是市场拓展、客户互动和数据收集的重要工具。精心打造和优化企业官网,能够为企业在海外市场的发展提供强大的支持。

WordPress子页面自动调用父页面的模板

一段简洁的代码就可以实现,WordPress子页面自动调用父页面的模板。

造成wordpress入侵的主要原因

使用wordpress建站的人几乎都遇到过wordpress网站被入侵的情况,,网站安全问题是头等大事。