WordPress如何自定义文章详情页模板

   2025-07-28 admin00100

如果想让某个分类的文章页面样式有别于其它分类,我们可以使用自定义的模板的方法实现。例如,我们准备让名称为wordpress的分类文章使用有别于其它分类的模板样式,

首先在所用主题根目录新建一个名称single-wordpress.php的模板文件。将以下代码片段添加到您的当前主题的functions.php文件:

add_action('template_include','load_single_template');functionload_single_template($template){$new_template='';//singleposttemplateif(is_single()){global$post;//'wordpress'iscategoryslugsif(has_term('wordpress','category',$post)){//usetemplatefilesingle-wordpress.php$new_template=locate_template(array('single-wordpress.php'));}}return(''!=$new_template)?$new_template:$template;}
 
举报收藏 0打赏 0评论 0
 
更多>同类资讯
推荐图文
推荐资讯
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  版权声明  |  网站地图  |  RSS订阅
Powered By DESTOON