首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用get_template_part的Post格式

问使用get_template_part的Post格式
EN

WordPress Development用户
提问于 2012-01-25 12:21:45
回答 1查看 1.4K关注 0票数 1

除了标准之外,我还设置了使用post格式的图片库和视频。我正在编辑循环-single.php,为每种post格式提供不同的布局,但我将为每种post格式包括get_template_part。

这就是我所拥有的:

代码语言:javascript
复制
<?php
/**
 * The loop that displays a single post.
 *
 * The loop displays the posts and the post content.  See
 * http://codex.wordpress.org/The_Loop to understand it and
 * http://codex.wordpress.org/Template_Tags to understand
 * the tags used in it.
 *
 * This can be overridden in child themes with loop-single.php.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.2
 */
?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>


<?php

    if ( has_post_format( 'gallery' )) {
      // code to display the gallery format post here

      get_template_part( 'news' 'gallery' ); // News Gallery Template (news-gallery.php) 

    } else if (has_post_format('video')) {
       // stuff to display the video format post here

        get_template_part( 'news' 'video' ); // News Gallery Template (news-video.php) 

    }else {
       // code to display the normal format post here

        get_template_part( 'news' 'standard' ); // News Gallery Template (news-standard.php) 

    }

    <?php endwhile; // end of the loop. ?>


?>

当我测试时,它出现了一个错误:

解析错误:语法错误,第26行/home/judddev/public_html/pitch/wp-content/themes/pitch/loop-single.php中的意外T_CONSTANT_ENCAPSED_STRING

任何帮助都将不胜感激。

EN

回答 1

WordPress Development用户

发布于 2012-01-25 12:48:19

get_template_part的参数中缺少一个逗号。

而不是<?php get_template_part( 'news' 'video' ); ?>,它应该是<?php get_template_part( 'news','video' ); ?>

票数 3
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/40102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档