cms网站内容如何自定义(白天教你使用自定义的文章详情页展示效果怎么办呢?)

优采云 发布时间: 2021-10-06 03:05

  cms网站内容如何自定义(白天教你使用自定义的文章详情页展示效果怎么办呢?)

  我厌倦了WordPress只有一个详细页面模板。如果我想为不同类别使用不同的文章详细信息页面,我应该怎么做?我将教你如何在白天使用自定义模板

  例如,在白天,我希望WordPress类别下的文章详细信息页面与内置模板页面不同

  实施方法:

  1、在网站主题根目录下创建一个新的文章详细信息页面模板文件,并在白天将其命名为single-wordpress.php(名称基于个人偏好,但需要英文名称)

  2、将以下代码添加到当前主题的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模板

  如果希望其他类别使用自定义模板,只需重复上述步骤

  过去的今天:文章最后修改时间为2020年6月2日23:06:23

  功能.phpwordpress分类

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线