当前位置:首页>网络教程>WordPress自定义文章详情页模板

WordPress自定义文章详情页模板

想要让某个特定分类文章页面样式区别于其他分类,我们可以自定义模板来实现。今天我们分享一下WordPress自定义文章详情页模 ...

想要让某个特定分类文章页面样式区别于其他分类,我们可以自定义模板来实现。今天我们分享一下WordPress自定义文章详情页模板,首先在所用WordPress主题根目录新建一个名称 single-wordpress" target="_blank">wordpress.php的模板文件。

WordPress自定义文章详情页模板

将以下代码片段添加到您的当前主题的 functions.php 文件:

add_action(‘template_include’, ‘load_single_template’);

function load_single_template($template) {

$new_template = ”;

// single post template

if( is_single() ) {

global $post;

// ‘wordpress’ is category slugs

if( has_term(‘wordpress’, ‘category’, $post) ) {

// use template file single-wordpress.php

$new_template = locate_template(array(‘single-wordpress.php’ ));

}

}

return (” != $new_template) ? $new_template : $template;

}

上面的代码将指定WordPress分类的文章,使用 single-wordpress.php 模板文件。同理,你可以重复以上的步骤,让其它分类也可以使用自定义模板。

给TA打赏
共{{data.count}}人
人已打赏
网络教程

WordPress开发中如何添加网站头部数据?

2022-7-15 19:06:20

网络教程

wordpress网站的常规设置

2022-7-15 19:06:45

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索