WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Twenty Twelve not displaying summary or manual posts excerpts (39 posts)

  1. ChrisColston
    Member
    Posted 1 year ago #

    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.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    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.

  3. ChrisColston
    Member
    Posted 1 year ago #

    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

  4. 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().

  5. ChrisColston
    Member
    Posted 1 year ago #

    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?

  6. 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.

  7. ChrisColston
    Member
    Posted 1 year ago #

    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

  8. 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!)

  9. ChrisColston
    Member
    Posted 1 year ago #

    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

  10. ChrisColston
    Member
    Posted 1 year ago #

    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

  11. jkshay
    Member
    Posted 1 year ago #

    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.

  12. dianabyron
    Member
    Posted 1 year ago #

    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?

  13. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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

  14. dianabyron
    Member
    Posted 1 year ago #

    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.

  15. dianabyron
    Member
    Posted 1 year ago #

    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; ?>
  16. dianabyron
    Member
    Posted 1 year ago #

    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; ?>
  17. dianabyron
    Member
    Posted 1 year ago #

    ALCHYMYTH -
    I tried your bit of code for content.php (had to use my imagination a bit to figure out what to put where - made a hybrid of your code and mine - and it worked! Posts are excerpted. But too short. So I made a functions.php that had just:

    <?php
    function twentytwelvechild_custom_excerpt_length( $length ) {
    	return 100;
    }
    add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 100 );
    
    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');
    
    ?>

    And my website went belly-up with the following message:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING in /home/diann/public_html/wp-content/themes/twentytwelve-child/functions.php on line 9 (which is the return ' <a href="'. get_permalink($post->ID) . '">Read the Rest...</a>'; line. Did it go belly-up because my content.php already has a call to the permalink and a "Read More" in it, and they kind of got into a fight?

  18. dianabyron
    Member
    Posted 1 year ago #

    oops! that was supposed to be:
    return ' ID) . '">Read the Rest...';
    line (code already had backticks, so this post got it wrong).

  19. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    my mistake (a stray ' before the function name twentytwelvechild_new_excerpt_more);

    the filter code should read:

    <?php
    function twentytwelvechild_custom_excerpt_length( $length ) {
    	return 100;
    }
    add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 100 );
    
    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');
    
    ?>
  20. dianabyron
    Member
    Posted 1 year ago #

    Thanks, I'll take that out.
    However I've got a new prob - the active link Read More comes AFTER the facebook twitter and google+ like buttons! The plugin really-simple-facebook-twitter-share-buttons.2.9.2 required its shortcode to be placed at the end of the post in the post body. The excerpt function evidently doesn't recognize that this is not actually part of the post, and yet puts it after the [....]. Have you any suggestions on how I can get the Read More to come right after the [....] and before the like buttons?

  21. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try playing with different priorities for the filter:

    example:

    add_filter('excerpt_more', 'twentytwelvechild_new_excerpt_more', 5);

    http://codex.wordpress.org/Function_Reference/add_filter

  22. dianabyron
    Member
    Posted 1 year ago #

    First I uploaded the functions.php with your amended text (without the odd backtick) to my child theme and again my website went belly-up with:
    Parse error: syntax error, unexpected '{' in /home/diann/public_html/wp-content/themes/twentytwelve-child/functions.php on line 12

  23. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    this time, I am innocent ;-(

    the code is correct (just tested), and there should be nothing in line 12.

  24. dianabyron
    Member
    Posted 1 year ago #

    Dunno then....

  25. dianabyron
    Member
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/add_filter is totally over my head.
    All I can get is wondering whether my child functions.php code should end in ?> or ;
    Any clues?
    (the error was on line 13, and line 13 is only "?>" like the end of lots of php lines)

  26. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    could you post the full code of functions.php as it is now?

  27. dianabyron
    Member
    Posted 1 year ago #

    Here is the full code of the child theme functions.php.
    However in testing, I discovered something that was causing the parse errors.
    In Text Edit I had coloured some text to be able to see groups in the strings easily while editing. Then when the file was converted to a .php, although I could not see any change in the code when opening it with Text Edit, if opened with Dreamweaver (to show line numbers) there was a ton of font markup. So I got rid of that, and now the functions.php does NOT cause a parse error, the site loads OK
    BUT the post excerpt length hasn't changed!
    So that 100 in there is not making any difference. Is there somewhere/someway else that the longer post excerpt length has to be specified?
    Thanks for helping, Alchymyth

    <?php
    function twentytwelvechild_custom_excerpt_length( $length ) {
    	return 100;
    }
    add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 100 );
    
    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');
    
    ?>
  28. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    I am at a loss here - the code to change the excerpt length works in my test child theme of Twenty Twelve;

    do you have any plugins activated which might influence the excerpts?

    standard trouble shooting procedure:
    try to deactivate all plugins to see if that solves the problem;
    then reactivate one plugin at a time to locate the interfering one.

  29. dianabyron
    Member
    Posted 1 year ago #

    I did that. No problem with plugins.

  30. dianabyron
    Member
    Posted 1 year ago #

    Could you please send me the exact, complete functions.php code that you have in your Twenty Twelve for me to try?

Topic Closed

This topic has been closed to new replies.

About this Topic