请帮助了解我添加此代码后Single.php崩溃的原因

时间:2016-05-12 作者:user1982485

这是我的单曲。php。我正在使用Suffusion主题和高级自定义字段插件。

我正在尝试显示基于特定帖子类别的自定义字段。如果我删除php标记和if语句,代码就可以正常工作,但自定义字段会显示在每篇文章中。如果添加php标记,页面就会崩溃。

我将“我的代码从这里开始”和“我的代码在这里结束”标记出来,供您查找我的代码。如果可能,请帮助。

    <?php
    /**
     * This is the template file for single posts. It is used by single posts of any post type.
     *
     */
    get_header();
    ?>
        <div id="main-col">
            <?php suffusion_before_begin_content(); ?>
        <div id="content">
    <?php
    global $post, $suffusion_is_cpt;
    if ($post->post_type != \'post\') {
        $suffusion_is_cpt = true;
        add_filter(\'suffusion_byline_position\', \'suffusion_single_cpt_byline_position\');
        add_action(\'suffusion_add_taxonomy_bylines_line\', \'suffusion_cpt_line_taxonomies\', 10, 2);
        add_action(\'suffusion_add_taxonomy_bylines_pullout\', \'suffusion_cpt_line_taxonomies\', 10, 4);
        global $suffusion_cpt_layouts, $suf_cpt_bylines_posted_by, $suf_cpt_bylines_comments, $suf_cpt_bylines_permalinks, $suf_cpt_bylines_post_date;
        if (isset($suffusion_cpt_layouts[$post->post_type]) && isset($suffusion_cpt_layouts[$post->post_type][\'byline-contents\'])) {
            $byline_contents = explode(\',\', $suffusion_cpt_layouts[$post->post_type][\'byline-contents\']);
            $suf_cpt_bylines_posted_by = in_array(\'posted-by\', $byline_contents) ? \'show\' : \'hide\';
            $suf_cpt_bylines_comments = in_array(\'comments\', $byline_contents) ? \'show\' : \'hide\';
            $suf_cpt_bylines_permalinks = in_array(\'permalink\', $byline_contents) ? \'show\' : \'hide\';
            $suf_cpt_bylines_post_date = in_array(\'date\', $byline_contents) ? \'show\' : \'hide\';
        }
        else {
            $suf_cpt_bylines_posted_by = false;
            $suf_cpt_bylines_comments = false;
            $suf_cpt_bylines_permalinks = false;
            $suf_cpt_bylines_post_date = false;
        }
    }

    if (have_posts()) {
        while (have_posts()) {
            the_post();
            global $suf_prev_next_above_below;
            if ($suf_prev_next_above_below == \'above\' || $suf_prev_next_above_below == \'above-below\') {
                get_template_part(\'custom/prev-next\');
            }
            $original_post = $post;
            do_action(\'suffusion_before_post\', $post->ID, \'blog\', 1);
    ?>
        <article <?php post_class();?> id="post-<?php the_ID(); ?>">
    <?php
            suffusion_after_begin_post();
        ?>
            <div class="entry-container fix">
                <div class="entry fix">
    <?php
            suffusion_content();

    ?>
                </div><!--/entry -->


    //MY CODE STARTS HERE!!!!!!!!!!!!!!
    <?php
    if (in_category(\'movies\')){
    <span style="font-size:16px">
    <strong>Movie:</strong> <?php the_field(\'movie_name\'); ?> (<?php the_field(\'movie_year\'); ?>)<br/>
    <strong>IMDb:</strong> <?php the_field(\'imdb_link\'); ?><br/>
    <strong>Rotten Tomatoes: <?php the_field(\'rt_link\'); ?> <br/><br/>
    </span>
    <br/><br/>
    }
?>
    //MY CODE ENDS HERE!!!!!!!!!!!!!!

    <?php
            // Due to the inclusion of Ad Hoc Widgets the global variable $post might have got changed. We will reset it to the original value.
            $post = $original_post;
            suffusion_after_content();
    ?>
            </div><!-- .entry-container -->
    <?php
            suffusion_before_end_post();
            comments_template();
    ?>
        </article><!--/post -->
    <?php
            do_action(\'suffusion_after_post\', $post->ID, \'blog\', 1);
            if ($suf_prev_next_above_below == \'below\' || $suf_prev_next_above_below == \'above-below\') {
                get_template_part(\'custom/prev-next\');
            }
        }
    }
    else {
    ?>
            <article class="post fix">
            <p><?php _e(\'Sorry, no posts matched your criteria.\', \'suffusion\'); ?></p>
            </article><!--post -->

    <?php
    }
    ?>
          </div><!-- content -->
        </div><!-- main col -->
    <?php
    get_footer();
    ?>
}

1 个回复
最合适的回答,由SO网友:N00b 整理而成

你失踪了<?php?>

<?php

if( in_category( \'movies\' ) ) {    // this (end php, start html) -> ?> 

    <span style="font-size:16px">
        <strong>Movie:</strong> <?php the_field( \'movie_name\' ); ?> (<?php the_field( \'movie_year\' ); ?>)<br/>
        <strong>IMDb:</strong> <?php the_field( \'imdb_link\' ); ?><br/>
        <strong>Rotten Tomatoes: <?php the_field( \'rt_link\' ); ?> <br/><br/>
    </span>
    <br/><br/> <?php // <- this (end html, start php)
} ?>