傻大憨

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外贸建站平台以其简便、灵活的特点成为许多企业打造专业网站的首选工具。在这篇文章中,我们将… Continue reading WordPress外贸建站教程实用技巧分享

WordPress外贸网站建设的核心元素与实际案例

  在竞争激烈的外贸市场中,成功建设一个专业且高效的WordPress外贸网站需要精心策划和正确实施。本文将深… Continue reading WordPress外贸网站建设的核心元素与实际案例

wordpress子分类调用父分类名称和链接

子分类与父分类名称和链接调用相关

用wordpress模板几百元就可以自己建网站

使用WordPress模板搭建独立站是一种成本较低且操作简便的选择,尤其适合预算有限且希望快速上线的用户。

为wordpress后台添加一个自定义页面

给wordpress后台添加一个自定义页面,一个所有用户可见,一个只有编辑权限的用户可见。

禁用WordPress中的搜索功能

以下代码可以禁止使用wordpress中的搜索功能