Wordpress:需要添加特定于帖子的代码以避免出现在索引和主页中

I'm new to this but I'm trying to add some Wordpress code for ACF that works in one theme to another theme that is set-up slightly differently.

The code adds repeating list items to the post using the ACF plugin.

The new theme uses a single part - content.php to generate output for both the index pages and the singular post page. On the previous theme there was single.php which as its name suggests contained the single post code ao I just dropped the code in there without issue and it didn't effect the index pages.

The bit of content.php on the new theme I need to edit looks like this...

    <div class="entry-content">
    <?php

    // On archive views, display post thumbnail, if available, and       excerpt.
    if ( ! is_singular() ) {

        if ( has_post_thumbnail() ) { ?>

            <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Link to %s', 'alienship' ), the_title_attribute( 'echo=0' ) ); ?>">
                <?php echo get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'class' => 'alignleft', 'title' => "" ) ); ?>
            </a>
        <?php
        } // has_post_thumbnail()

        the_excerpt();

    } // if ( ! is_singular() )

    // On singular views, display post thumbnails in the post body if it's not big enough to be a header image
    else {
        $header_image = alienship_get_header_image( get_the_ID() );
        if ( has_post_thumbnail() && 'yes' != $header_image['featured'] ) { ?>

            <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Link to %s', 'alienship' ), the_title_attribute( 'echo=0' ) ); ?>">
                <?php echo get_the_post_thumbnail( $post->ID, 'medium', array( 'class' => 'alignright', 'title' => "" ) ); ?>
            </a>
        <?php
        }

        the_content();
    }

    wp_link_pages(); ?>
</div><!-- .entry-content -->

I need my code to appear below the_content and above wp_link_pages

Problem is my code starts of with its own If statement. See below:

        <!-- List Stuff Starts -->

        <?php if( have_rows('list_items') ): ?>



                <?php while( have_rows('list_items') ): the_row(); 

                    // vars
                $item_name = get_sub_field('item_name');
                $item_image = get_sub_field('item_image');
                $item_meta1_label = get_sub_field('item_meta_1_label');
                $item_meta1_content = get_sub_field('item_meta_1_content');
                $item_content = get_sub_field('item_content');
                $item_price = get_sub_field('item_price');
                $item_old_price = get_sub_field('item_old_price');
                $item_url = get_sub_field('item_url');
                ?>

                <div class="row blog-list-row">
                    <?php if($item_url): ?>
                    <div class="col-sm-4 mobile-center mobile-padding">
                        <a href="<?php echo $item_url; ?>" onclick="__gaTracker('send', 'event', 'outbound-list-image', '<?php echo $item_url; ?>', 'List Item Link');" alt="<?php echo $item_name; ?>" target="_blank"><img class="bloglistimage" src="<?php echo $item_image['url']; ?>" alt="<?php echo $item_name; ?>" /></a></div>
                    <?php else: ?>  
            <div class="col-sm-4 mobile-center mobile-padding">         <img class="bloglistimage" alt="<?php echo $item_name; ?>" src="<?php echo $item_image['url']; ?>" /> </div>
                    <?php endif; ?> 

<div class="col-sm-8">
                    <?php if( $item_name ): ?>
                        <h3 class="nmt pull-left"><?php echo $item_name; ?></h3>
                        <?php endif; ?>
                        <div class="clearing"></div>
                    <?php if( $item_price ): ?>
                                <p class="bloglist-price"><span class="blogpricelabel">Price: </span><span class="blogpriceprice">£<?php echo number_format((float)$item_price, 2, '.', ''); ?></span></p>
                            <?php endif; ?>

                            <?php if( $item_old_price ): ?>
                                <p class="old-price"><span class="blogpricelabel">Was: </span><span style="text-decoration: line-through;font-size: 0.9em;" class="bloglist-oldprice">£<?php echo number_format((float)$item_old_price, 2, '.', ''); ?></span></p>
                            <?php endif; ?>

                            <?php if( $item_meta1_label ): ?>
                                <p class="bloglist-meta"><span class="blogmetalabel"><?php echo $item_meta1_label; ?>&nbsp;</span><span class="blogmetacontent"><?php echo $item_meta1_content; ?></span></p>
                            <?php endif; ?>

                            <span class="item-copy"><?php echo $item_content; ?></span>



                            <?php if( $item_url ): ?>

                                <a class="btn btn-xs btn-default pull-right" href="<?php echo $item_url ?>" onclick="__gaTracker('send', 'event', 'outbound-list-button', '<?php echo $item_url; ?>', 'List Item Button');"><span class="button-text">Find Out More...</span></a>   

 <?php endif; ?>
  </div>
                </div>

                        <?php endwhile; ?>



            <?php endif; ?>

            <!-- List Stuff Ends -->

At the moment my code works on the post page, but it also outputs the custom fields below the headline, thumbnail and excerpt on the index and home pages. I just want the code to appear on the single post page, I'm guessing by placing it within the Else part of the code.

But when I just drop it in the blog page breaks. I know it's a question of syntax and ensuring the right {} are in the right place, but I'm struggling to get them in the right place and the right order.

Any help, guidance or pointers gratefully received. Cheers....

You could copy that file and rename it single.php. Once you've done that you can insert your code and it should then use that template for the single post pages.

An easier option is to include an "if" statement that encapsulates your code that checks if it is the home page or not.

if(!is_home()){ 
//your code here
}

This will only execute your code if the page is not the homepage