傻大憨

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是一个关注跨境电商、创业话题的网站。

The best foreign trade website building company in Shenzhen

Waimaoyes is a company specializing in foreign trade website construction, mainly providing WordPress multilingual foreign trade small language website construction services.

The best independent website building platform for foreign trade

The best template website building platform

Jianzhanpress themes are the best Chinese WordPress themes to use

Jianzhanpress.com themes are the best Chinese WordPress themes to use

wordpress外贸建站2B或2C如何选

wordpress外贸建站,就是外贸公司用免费开源好用的wordpress系统,为自己的公司搭建一个网站。因页… Continue reading wordpress外贸建站2B或2C如何选

wordpress指定父分类调用子分类名称

在任意位置都可以实现,指定ID父分类调用子分类名称

wordpress任意位置调用指定ID页面的内容

在制作wordpress主题时,有时需要在一些位置调用一些特殊页面的内容。比如,在某个位置调用一段简介之类的。