SOHO创业

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 SOHO

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

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

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

wordpress调用最新文章

wordpress按栏目调用最新文章

一款专为高端制造业设计的WordPress外贸主题

Sora索拉是一款专为高端制造业设计的WordPress外贸主题,用于建立专业的品牌形象和在线展示其产品。

什么样的人不适合用wordpress模板建站?

上一篇写了什么样的网站不适合使用WordPress?今天再写一个什么样的人不适合使用wordpress搭建网站。

WP最主题

WP最主题以简洁、高效的风格著称,其开发的主题通常具有快速的加载速度和良好的兼容性。适合追求简洁设计、注重网站性能的用户,能够帮助用户快速搭建出专业且高效的网站。

wordpress搜索自字义字段内容

有些网站需要根据自定义段字的内容来做为搜索项,比如,房产中介公司wordpress网站,需要搜索同一区域内容的楼盘,然后展示出内容。