SOHO创业

为不同文章形式选择不同的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 SOHO

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

wordpress建站费用明细

WordPress建站的主要费用包括域名、托管、主题、插件和其他相关费用,如SSL等。‌

WordPress外贸网站建设的核心元素与实际案例

  在竞争激烈的外贸市场中,成功建设一个专业且高效的WordPress外贸网站需要精心策划和正确实施。本文将深… Continue reading WordPress外贸网站建设的核心元素与实际案例

wordpress获取父页面的2种方法

wordpress模板制作的过程中有时会用到获取父页面的ID,下面是wordpress获取父页面的2种方法。

怎么选择一个靠谱的wordpress建站公司

拥有一个功能强大、设计精美的网站对于企业来说至关重要。无论是展示品牌形象、推广产品,还是与客户互动,网站都是企… Continue reading 怎么选择一个靠谱的wordpress建站公司

WordPress调用指定分类文章

按指定分类调用wordpress文章

开源程序wordpress在海外品牌推广中的重要作用

WordPress作为全球最流行的开源内容管理系统(CMS),在全球网站搭建中占据超过40%的市场份额。