傻大憨

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企业网站 就用WP快主题

快速搭建wordpress企业网站就用WP快主题,以下是WP快主题建站的10大优势。

推荐3个建网站的模板平台

可以免费下载网站模板的网站

海归创业者喜欢用WordPress搭建公司官网

随着全球化的推进和科技的飞速发展,越来越多的海归创业者选择回国发展,他们不仅带回了丰富的国际经验和资源,也带来… Continue reading 海归创业者喜欢用WordPress搭建公司官网

wordpress按栏目别名调用最新内容

可实现按栏目别名调用该栏目下的最新内容

wordpress数据库批量替换网址最简单的方法

在搭建wordpress网站时,常常会用到批量替换网址,网上能搜到挺多的方法,基本都是通过数据库管理后台来批量替换的。

wordpress禁用xmlrpc

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