Support » Themes and Templates » Twenty Twelve not displaying summary or manual posts excerpts

  • Resolved ChrisColston

    (@chriscolston)


    I’m having real difficulty displaying summarys for posts on the front page (blog roll).
    I’ve tried adding the following to functions.php

    function excerpt_read_more_link($output) {
     global $post;
     return $output . '<a href="'. get_permalink($post->ID) . '"> Read More...</a>';
    }
    add_filter('the_excerpt', 'excerpt_read_more_link');

    but to no avail.

Viewing 15 replies - 1 through 15 (of 38 total)
  • esmi

    (@esmi)

    Forum Moderator

    Do not edit the Twenty Twelve theme. It will be the default theme in WordPress 3.5 and having access to an unedited version of the theme is vital when dealing with a range of site issues. First create a child theme for your changes.

    Thanks esmi, I’m actually just using twenty twelve to try to get this to work so I’m not too bothered about editing this at the moment, I’ve also tried it with twenty eleven so am not convinced it’s a theme issue. I already have a Child theme set up

    The basic issue is that the code you posted above doesn’t do what it sounds like you want it to do. All that code does is replace the “[…]” at the end with the phrase “Read More” whenever the excerpt is displayed. But what you haven’t done is tell your theme to display excerpts instead of full posts.

    For that, you need to copy the content.php file from twentytwelve into your child theme folder, and then edit the child version to replace the call to the_content() with the_excerpt().

    Thanks Amy, got that working and added my original code to functions.php but now only excerpts are displayed throughout and not the full article?

    Sorry! When you said “display summaries on the front page”, I thought that’s what you meant — to show excerpts instead of full posts. It’s a common request, and I misread.

    So, what is it that you want to do? Where on the site are there full posts that you’d rather see as excerpts?

    Wherever it is, the basic process of switching the_excerpt() for the_content() is going to be the same, but I’ll need more information to help you hunt down just how to do it.

    You may also want to read up on Theme Development in general and the Template Hierarchy in particular. The Template Hierarchy is a little tricky at first, but it’s really worth understanding the concept if you’re going to get into theme development — that’s how WordPress determines which files to use (and thus which ones to edit!) depending on where on the site you are and what kind of content you’re trying to display.

    Thanks Amy. I’ll try better to explain this. So this is what I’m trying to achieve

    momma mock up

    Now I (wrongly) assumed that by going from the dashboard>settings>reading and setting the front page to ‘your latest posts’ and for ‘summary’ to display, this would evoke the mythical post with a 55 character excerpt and a ‘readmore’ option which links to the full post. It obviously doesn’t so I guess what I need to do, as you say is to switch the_content() for the_excerpt(), but which template displays the ‘latest posts’, I think this is what I need to do.

    I’ve found within the twenty twelve theme page-templates/front-page.php
    and the line:

    <?php get_template_part( 'content', 'page' ); ?>
    and tried in vain to change ‘content’ to ‘excerpt’ but I’m guessing it’s not quite that straight forward

    Sorry I’m a bit of a newbie with WP, much happier with a css file

    Yeah, that’s a whole different content! the_content() is a function that, basically, says “put the chunk of content I created in the editor right here”. The “content” in that get_template_part() function you quoted is a label (technically, it’s an argument, but let’s not worry about that) that says “use the file called content-page”.

    You could edit content-page.php, but I don’t recommend it, because that’s going to affect all your pages, and that probably isn’t what you want.

    A better option would be

    1. Create a new file for what you want. You can make a copy of the parent theme’s content-page.php since you just want to make this one change — but name it something else, like content-front.php, or whatever else you like.
    2. Make your changes in your new file (change the_content() to the_excerpt()
    3. Edit front-page.php (in your child theme, of course!) so that the get_template_part() call you already found says <?php get_template_part( 'content', 'front' ); ?> instead.

    And then give yourself a big pat on the back/buy yourself a beer/whatever’s appropriate, because you’ve leveled up from just messing with the css!

    (Oh: a quick disclaimer – the above is totally untested, but the general procedure is right. If you run into trouble, please let me know!)

    Cool, think I follow. Will simply creating a copy of front-page.php and placing it in the child theme be enough? as it’s original is in another directory. Not quite au fait with the hierarchy and how things are called and when

    Amy, it worked!!
    http://www.mommaloves.net/
    thanks so much, I think I’ve earned that beer!
    just need to append the featured image now!

    incidently, if you know, how would I add a css class to ‘excerpt’, I’m not quite sure of the best practice with so many ways of achieving the desired effect in WP

    ChrisColston-

    I too made the same assumption that changing Settings–> Reading–> For each article in a feed, show… from “Full text” to “Summary” would produce summaries of my articles on my home page. I’m migrating from Drupal to WordPress and had this functionality on my Drupal-based site.

    It has come to my attention that this setting is actually for RSS feeds, and therefore changing this value would not by default change the appearance of articles on the blog roll.

    Regardless, glad to see you got a solution to your problem. I think I’ll be implementing this same solution.

    dianabyron

    (@diannetrussell)

    Amy, I have a question about your method of replacing the_content() with the_excerpt().
    What I want to do is, ONLY on my blog homepage, shorten the posts and have Read More…..
    I’m new and don’t understand the excerpt thing.
    But I did find some relevant-looking code in my content.php file:

    [review how to post code – http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

    <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">→</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

    I have my child theme folder ready to go with functioning style.css, but I don’t know what to do with the above code. I can see the_excerpt() but not the_content().
    And how would I tell it how short to make the posts, and tell it to do that to all the posts?

    ONLY on my blog homepage, shorten the posts and have Read More…..

    create a copy of content.php in your child theme.
    edit that code section (actually including a few lines before the section), to look like:

    <?php if ( is_search() || is_home() ) : // 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">→</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

    I can see the_excerpt() but not the_content().

    the_content() in this case has some parameters in the brackets – this is the line:

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

    the change of the conditional statement includes all posts page posts to show the excerpt.

    how would I tell it how short to make the posts, and tell it to do that to all the posts?

    it will be automatically the same for all posts;
    create a functions.php in your child theme; add the <?php in the first line and the ?> in the last line;
    inbetween, add for example:

    function twentytwelvechild_custom_excerpt_length( $length ) {
    	return 40;
    }
    add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 20 );
    
    function twentytwelvechild_new_excerpt_more($more) {
           global $post;
    	return ' <a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
    }
    add_filter('excerpt_more', 'twentytwelvechild_new_excerpt_more');

    [edit: typo corrected in the code above]

    http://codex.wordpress.org/Function_Reference/the_excerpt
    http://codex.wordpress.org/Function_Reference/the_excerpt#Control_Excerpt_Length_using_Filters
    http://codex.wordpress.org/Function_Reference/the_excerpt#Make_the_.22read_more.22_link_to_the_post

    dianabyron

    (@diannetrussell)

    Hi Alchymyth, well you’ve moderately swept me off my feet! I’m going out right now but will get into that coding as soon as I get back. Thanks.

    dianabyron

    (@diannetrussell)

    Good morning Alchymyth (or at least it’s 9:30 in the morning where I am):
    I opened up a copy of my current content.php from my child theme folder.
    The code in mine differs from what you’ve posted.
    Going through it (not really understanding it but starting to recognize some patterns) it looks as if yours has nothing to call for the permalink of the full post, or a Read More? You have this in the code to change in functions.php.
    However my contents.php already has a call for the permalink in conjunction with Read More.
    But it’s not working – is that because it does NOT have the bit you’ve shown with content(_(Continue reading etc ?
    So perhaps all I need to do is put that bit in content.php, leave function.php alone?

    YOUR CONTENT.PHP CODE:

    <?php if ( is_search() || is_home() ) : // 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; ?>

    MY CONTENT.PHP CODE:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    <a href="<?php echo get_permalink(); ?>"> Read More...</a>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content (); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

    dianabyron

    (@diannetrussell)

    Good morning Alchymyth (or at least it’s 9:30 in the morning where I am):
    I opened up a copy of my current content.php from my child theme folder.
    The code in mine differs from what you’ve posted.
    Going through it (not really understanding it but starting to recognize some patterns) it looks as if yours has nothing to call for the permalink of the full post, or a Read More? You have this in the code to change in functions.php.
    However my contents.php already has a call for the permalink in conjunction with Read More.
    But it’s not working – is that because it does NOT have the bit you’ve shown with content(_(Continue reading etc ?
    So perhaps all I need to do is put that bit in content.php, leave function.php alone?

    YOUR CONTENT.PHP CODE:

    <?php if ( is_search() || is_home() ) : // 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; ?>

    MY CONTENT.PHP CODE:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    <a href="<?php echo get_permalink(); ?>"> Read More...</a>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content (); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

Viewing 15 replies - 1 through 15 (of 38 total)
  • The topic ‘Twenty Twelve not displaying summary or manual posts excerpts’ is closed to new replies.