php文章详情页排版,WordPress自定义文章详情页模板

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

38638cf4cce9f0e2f12c7bc38ce6150d.png

将以下代码片段添加到您的当前主题的 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 模板文件。同理,你可以重复以上的步骤,让其它分类也可以使用自定义模板。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值