傻大憨

根据不同的分类调用指定的不同single模板

在wordpress的functions.php中,添加以下代码,即可实现根据不同的分类别名,调用指定的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-news.php' ));
        }
 // 案例
 if( has_term(array('case', 'case1', 'case2', 'case3', 'case4'), 'category', $post) ) {
 $new_template = locate_template(array('single-case.php' ));
        }

     }
 return ('' != $new_template) ? $new_template : $template;
 }
Published
Categorized as 建站知识 Tagged ,

By 傻大憨

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

想了解模板之家mymoban的模板在移动端的适配情况如何

模板之家(MyMoban.com)作为一个专业的网站模板提供商,通常会非常重视移动端的适配情况,因为随着移动互… Continue reading 想了解模板之家mymoban的模板在移动端的适配情况如何

GGD独立站的10大优势

GGD独立站,即Google独立站,是一种依托Google生态系统进行营销推广的跨境电商独立站模式。

WooCommerce商城主题的安全性决定跨境电商之路能不能更稳 更远

WooCommerce以其开源、灵活、功能强大的特点,成为众多商家进军电商领域的首选工具。然而,在搭建WooCommerce商城的过程中,一个经常被忽视却至关重要的问题,就是WooCommerce商城主题的安全性。

为什么说GGD模式“最靠谱”

GGD独立站模式为跨境电商卖家提供了一种高效、精准且灵活的运营推广方式,通过充分利用Google生态系统的资源和工具,能够有效提升独立站的运营效果和市场竞争力。

NeveTheme轻量级古腾堡(Gutenberg)区块主题

NeveTheme是一款专为跨境电商独立站量身打造的高速、轻量级古腾堡(Gutenberg)区块主题。

wordpress禁用Rest API

将以下代码插入到functions.php文件中即可禁用Rest API