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

文心一言与SORA在WP企业网站程序开发中的对比

本文将对比文心一言与SORA在WordPress企业网站首页程序开发中的应用,并深入探讨文心一言在这一领域的优势。

获取wordpress某个栏目的内容数量

在制作wordpress模板时,有时会需要调用某个分类目录下的所有内容数量,通过这段简洁的代码就可以实现。

简站wordpress主题的三大特点

简站wordpress主题的三大特点 1、理念“崇尚简约、鄙视繁琐、化繁为简、实用即可。”简站wordpres… Continue reading 简站wordpress主题的三大特点

wordpress怎么调用页面别名

在制作wordpress主题时常常会用到调用页面的别名,下面这段代码可以完美解决,wordpress页面别名调用的问题。

用AI视频工具HeyGen可以给产品做视频介绍

做外贸跨境电商的人有福了 最近发现一款非常容易上手的AI视频工具HeyGen,通过HeyGen,可以在上传产品… Continue reading 用AI视频工具HeyGen可以给产品做视频介绍

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

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