Wordpress:使用get_template_part发布格式化单循环.php

时间:2012-01-25 12:28:44

标签: php wordpress

除了标准之外,我还设置了使用帖子格式库和视频。我正在编辑loop-single.php,为每种帖子格式提供不同的布局,但我要为每种帖子格式包含get_template_part。

这就是我所拥有的:

<?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

非常感谢任何帮助。

3 个答案:

答案 0 :(得分:1)

之间添加逗号

get_template_part('news','gallery');

答案 1 :(得分:0)

添加逗号:

get_template_part( 'news', 'gallery' );
                 here ___^

以及对get_template_part

的其他调用

答案 2 :(得分:0)

<?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; ?>

只需要从中切换这些:

 <?php endwhile; ?>


    ?>

到这个

?>

    <?php endwhile; ?>