傻大憨

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外贸网站建设的成功因素与技术点

  在竞争激烈的网络环境中,打造一家成功的外贸网站需要精心规划和技术实力。本文将揭晓一些成功建站的秘籍,重点聚… Continue reading WordPress外贸网站建设的成功因素与技术点

WordPress调用指定父分类下的子分类

使用循环的嵌套来实现WordPress调用指定ID父分类下的子分类

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

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

天津进出品贸易公司官网建站方案

在实施建站方案之前,建议与专业的建站公司或团队进行沟通和咨询,获取更详细和准确的建议。

WordPress外贸建站平台的最佳实践

  在构建WordPress外贸网站时,深入了解和正确应用核心功能是确保网站成功的关键。本文将解析WordPr… Continue reading WordPress外贸建站平台的最佳实践

自己动手为wordpress写一个反馈表单的代码

自己动手写一个WordPress反馈表单的代码,可以实现通过电子邮件接收提交的数据。