WordPress.org

Ready to get started?Download WordPress

Forums

How to add an excerpt (4 posts)

  1. mrling
    Member
    Posted 1 year ago #

    Site: jakespharler.com
    Theme: Child-Twentytwelve

    Recently want to turn my posts into excerpts, and tried doing this by writing in the excerpt box on the 'edit post' screen in dashboard. However, it seems this is not possible until I replace <?php the_content; ?> with <?php the_excerpt; ?> which according to various web sources, is located in the theme's index.php file. However, I couldn't find this in mine, but found it in the content.php file after finding this: http://wordpress.stackexchange.com/questions/22123/twenty-eleven-home-page-show-only-excerpt
    So...after copying the file into my child theme, I commented out the <?php the_content; ?> and replaced it with <?php the_excerpt; ?>. After saving, I loaded the page to find that my page is still showing the full post and no excerpt...anybody know what I am doing wrong?

    Thanks for your time!

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    unfortunately, you haven't posted your edited code;

    this is the section in content.php of Twenty Twelve:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

    this is the line that would need chnaging:

    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>

    alternatively, you could make the changes by edting the conditional statement; from:
    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    to:
    <?php if ( is_search() || is_home() || is_archive() ) : // Only display Excerpts for Search, Posts Page, Archives ?>

    http://codex.wordpress.org/Conditional_Tags

    make sure to save the file after the changes;
    make sure to edit the copy of content.php in your child theme ...

  3. dotnordic
    Member
    Posted 1 year ago #

    Twentytwelve has many different post formats. All the template files that start with content- are used to display posts of different formats.

    You don't need to change any code to use excerpts with Twentytwelve though. Just insert <!--more--> in the page where you want the page to break in two parts and only the part before that code will be displayed in the blog.

  4. mrling
    Member
    Posted 1 year ago #

    @alchymth:
    The directions that you suggestion are exactly what I tried that did not work, with the exception of the alternative technique which I will try soon. Also, maybe It would make a difference that I was trying to make these changes on my localhost with WAMP server? I don't know why it would be this though, since everything seems to be running fine (pages and links work)

    @dotnordic:
    I was considering using the <!--more--> tag, but don't want to do this with every single post, so that is why I am trying to edit the code.

Topic Closed

This topic has been closed to new replies.

About this Topic