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外贸网站建设的成功因素与技术点

  在竞争激烈的网络环境中,打造一家成功的外贸网站需要精心规划和技术实力。本文将揭晓一些成功建站的秘籍,重点聚… Continue reading WordPress外贸网站建设的成功因素与技术点

WP独立站受B2B的老板青睐 成一单就赚钱

WP独立站受外贸老板青睐,做B2B的站即便是一年成一单也赚钱,难怪老板们都搞那么多站。

WordPress外贸建站平台在市场的独特优势

  在建设外贸网站的众多选择中,WordPress凭借其卓越的特性和广泛的应用,成为全球外贸建站平台的领导者。… Continue reading WordPress外贸建站平台在市场的独特优势

使用wordpress搭建官网好处多于坏处

WordPress搭建官网的好处在多个方面都超过了其坏处,特别是在成本效益、社区支持、SEO性能以及灵活性和可定制性方面。

wordpress父页面调用子页面标题

在服务项目父页面通过以下代码,调用出子页面的标题

GGD独立站与DTC独立站并不是一回事

GGD独立站与DTC独立站各有优势和适用场景,企业应根据自身定位、资源和市场环境综合考虑选择合适的模式。