傻大憨

为不同文章形式选择不同的WordPress文章模板

在写文章的时候选择不同的文章形式,然后打开文章的时候会调用不同文章形式的模板。比如,文章形式为video ,就调用single-video.php模板,其它文章形式类似,可以添加多个文章样式。

//为不同文章形式的内容添加不同的single页面
add_action('template_include', 'load_single_template');
function load_single_template($template) {
  $new_template ='';
  // single post template
  if( is_single() ) {
    global $post;
    if ( has_post_format( 'video' )) {// 文章形式为video
      $new_template = locate_template(array('single-video.php' ));// 就调用single-video.php模板
    }
    if ( has_post_format( 'image' )) {// 文章形式为image
      $new_template = locate_template(array('single-image.php' ));// 就调用ssingle-image.php模板
    }
// 这里可以添加其他文章形式的模板
  }
  return (''!= $new_template) ? $new_template : $template;
}

将以上代码添加到functions.php文件中即可。

Published
Categorized as 建站知识 Tagged

By 傻大憨

shadahan.com是一个关注跨境电商、创业话题的网站。

wordpress主题二次开发时常用到的函数

wordpress常用函数大全

按分类调用标签 调用指定分类下的TAG

在制作wordpress主题时,有时候会用到按分类调用标签的时候,用上面的这一段代码就可以解决。

WordPress为某个分类添加特定的内容页模板

为某个分类目录category添加特定的内容页single模板

wordpress子分类调用父分类名称和链接

子分类与父分类名称和链接调用相关

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

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

我能否完全按照我的需求来设计wordpress网站

简站wordpress主题是我用过最简洁最好用的wordpress主题,简站主题的基础框架是固定的,呈现出来的东西,都在后台有对应修改的地方,使用起来非常方便。