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 - 16 through 30 (of 38 total)
  • 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?

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

    Michael

    (@alchymyth)


    Forum Moderator


    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');
    
    ?>

    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?

    Michael

    (@alchymyth)


    Forum Moderator


    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

    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

    Michael

    (@alchymyth)


    Forum Moderator


    this time, I am innocent ;-(

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

    Dunno then….

    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)

    Michael

    (@alchymyth)


    Forum Moderator


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

    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');
    
    ?>
    Michael

    (@alchymyth)


    Forum Moderator


    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.

    I did that. No problem with plugins.

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

    Michael

    (@alchymyth)


    Forum Moderator


    changing the excerpt length works (for me) with this functions.php in a child theme of Twenty Twelve:

    http://pastebin.com/QbnMkuJy

    as you seem to have Dreamweaver at hand, I would suggest to use it all the time as the editor to change any WordPress templates or files (and for the FTP connection) (this is what I do) instead of using any other text editor.

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