【问题标题】:Wordpress: Post Format single-loop.php using get_template_partWordpress:使用 get_template_part 发布格式 single-loop.php
【发布时间】:2012-01-25 12:28:44
【问题描述】:

除了标准之外,我还设置了使用库和视频的帖子格式。我正在编辑 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

任何帮助将不胜感激。

【问题讨论】:

  • get_template_part('新闻''画廊'); // 新闻图库模板 (news-gallery.php) Apprently

标签: php wordpress


【解决方案1】:

中间加逗号

get_template_part('新闻', '图库' );

【讨论】:

  • 出现新错误解析错误:语法错误,第 40 行 /public_html/pitch/wp-content/themes/pitch/loop-single.php 中的意外 '
  • 谢谢。最后不是这个。我有 在错误的地方。我会发布答案等等。
  • 好的,我的回答对你有用,然后点击右箭头接受我的回答。谢谢
【解决方案2】:

添加逗号:

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

以及对get_template_part的其他调用

【讨论】:

  • 出现新错误解析错误:语法错误,第 40 行 /public_html/pitch/wp-content/themes/pitch/loop-single.php 中的意外 '
【解决方案3】:
<?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; ?>

【讨论】:

    猜你喜欢
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    相关资源
    最近更新 更多