Forums

[resolved] Custom "continue reading" in Twentyten (26 posts)

  1. billbennett
    Member
    Posted 1 year ago #

    I've been looking at customising the 'continue reading' link in a Twentyten child theme - I managed to change the 'read more' link in an earlier theme, but it looks far more complex in Twentyten. Has anyone found out how to do this?

  2. Christine
    Moderator
    Posted 1 year ago #

    Look at the function.php file, line 241. The wording can be changed there.

  3. Root
    Member
    Posted 1 year ago #

    Far better to put the new function when u find it in functions.php in yr Child Theme IMHO. Never hack core files.

  4. Root
    Member
    Posted 1 year ago #

    Here u go

    // no more jumping for read more link
    function no_more_jumping($post) {
    	return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>';
    }
    add_filter('excerpt_more', 'no_more_jumping');
  5. billbennett
    Member
    Posted 1 year ago #

    Thanks. I should have been clearer. In my old theme I used custom fields to give each post a different 'read more'.

    This looks so much harder in Twentyten.

  6. Christine
    Moderator
    Posted 1 year ago #

    The Twenty ten theme is far more complex, but making child themes is much easier. As pointed out by Root, you could make a child theme with the new function, but I have no idea how to modify the function to read something different for each post.... sorry.

  7. Root
    Member
    Posted 1 year ago #

    Well there must be a function to do that somewhere......Looking at the function I posted you just need to add an array and rotate thru it ;)

  8. alchymyth
    The Sweeper
    Posted 1 year ago #

    /* Twenty Ten custom 'continue reading'
    /
    / custom field ($key = 'cont_read' ) dependant 'continue reading' text
    / alchymyth 2010
    */
    class Transformation_Text_Wrangler {
    function reading_more($translation, $text, $domain) {
    
    global $post;
      $cont_read = get_post_meta( $post->ID, 'cont_read', true );
      if( $cont_read ) :
        $cont_read = htmlentities($cont_read, ENT_QUOTES);
        $translations = &get_translations_for_domain( $domain );
        if ( $text == 'Continue reading <span class="meta-nav">&rarr;</span>' ) {
           return $translations->translate( $cont_read . ' <span class="meta-nav">&raquo;</span>' );
            }
        return $translation; // custom field value
      else :
        return $translation; // standard text
      endif;
     }
    }
    add_filter('gettext', array('Transformation_Text_Wrangler', 'reading_more'), 10, 4);

    extended, from:
    http://www.transformationpowertools.com/wordpress/read-more-in-twenty-ten-child-theme

  9. Root
    Member
    Posted 1 year ago #

    Very cool. Thanks ;)

  10. billbennett
    Member
    Posted 1 year ago #

    Would it be possible to pull the text for alternatives to "Continue reading" from a custom field?

  11. alchymyth
    The Sweeper
    Posted 1 year ago #

    that is exactly what the snippet posted earlier does:

    here is the line referring to the custom field:

    $cont_read = get_post_meta( $post->ID, 'cont_read', true );

  12. billbennett
    Member
    Posted 1 year ago #

    I'm sorry - I tried reading the code, but couldn't figure it out. (I'm not really a programmer at all).

  13. alchymyth
    The Sweeper
    Posted 1 year ago #

    no problem -
    it should work if you make a custom field with the key 'cont_read' and then enter your chosen text, what you would like to see instead of the 'continue reading'.

    the code also changes the arrow → &rarr; into »
    &raquo;

    did you get it to work?

  14. billbennett
    Member
    Posted 1 year ago #

    I've loaded the function into my child theme without a problem, but don't have it working properly yet. Will spend the later part of today trying to figure out why :-)

  15. billbennett
    Member
    Posted 1 year ago #

    It's hard to see why this isn't working.

    I've added the code to functions.php which is in the child theme directory.

    If I add a custom field entry it flashes yellow - which is a good sign.

    But continue reading doesn't change on the home page or on the archive pages.

  16. alchymyth
    The Sweeper
    Posted 1 year ago #

    do you save/update the custom field?
    do you update/save the post?

    is the custom field content still there if you go back and edit the post?

  17. billbennett
    Member
    Posted 1 year ago #

    Yes to all three.

    I tried searching for the content in the SQL database - and searching for the field name - I can't find either, but they MUST be there somewhere.

    Could there be a problem with the way the loop calls the function?:

    <div class="entry-content">
    				<?php the_excerpt( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
    				<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    			</div><!-- .entry-content -->
  18. alchymyth
    The Sweeper
    Posted 1 year ago #

    the_excerpt() has no parameter - the above code is and was always unexplained to me.

    the 'read-more' text for the excerpt comes from a function in functions.php of the twenty ten theme:

    /**
     * Adds a pretty "Continue Reading" link to custom post excerpts.
     *
     * To override this link in a child theme, remove the filter and add your own
     * function tied to the get_the_excerpt filter hook.
     *
     * @since Twenty Ten 1.0
     * @return string Excerpt with a pretty "Continue Reading" link
     */
    function twentyten_custom_excerpt_more( $output ) {
    	if ( has_excerpt() && ! is_attachment() ) {
    		$output .= twentyten_continue_reading_link();
    	}
    	return $output;
    }
    add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );

    and this:

    /**
     * Returns a "Continue Reading" link for excerpts
     *
     * @since Twenty Ten 1.0
     * @return string "Continue Reading" link
     */
    function twentyten_continue_reading_link() {
    	return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
    }

    if you haven't changed anything there, my suggested code should work (i would hope - tested in a child theme)

    you could paste the code of your functions.php into a http://wordpress.pastebin.com/ and post the link here for someone to check.

  19. billbennett
    Member
    Posted 1 year ago #

    Thanks

    I appreciate this, I also hope it will help others.

    Functions.php is saved at: http://wordpress.pastebin.com/wPVm5Q9M

  20. alchymyth
    The Sweeper
    Posted 1 year ago #

    this is the full functions.php of your child theme?

    have you changed anything in the functions.php of your parent theme, the Twenty Ten?

    you can also try:

    -change to the Twenty Ten theme and add the code directly into the functions.php of that theme;

    -deactivate all plugins, and when that solves the problem, re-activate one plugin after the other to see which triggers the problem.

    a link to your site might help to investigate this problem.

  21. billbennett
    Member
    Posted 1 year ago #

    Yes, that's it for functions.php - I had others previously, but have since stripped it back to nothing.

    I'm sure nothing is changed in the parent Twenty Ten functions, but to make certain, I'll reload a fresh file.

    I'll try making the change to the parent function.php file later - maybe later today.

    First I'm going to deactivate plug-ins and investigate this as a potential problem.

    My site is http://billbennett.co.nz

  22. billbennett
    Member
    Posted 1 year ago #

    Definitely not a plug in problem...just deactivated and nothing changed

  23. billbennett
    Member
    Posted 1 year ago #

    Moving the code to the parent functions.php didn't seem to make any difference.

  24. alchymyth
    The Sweeper
    Posted 1 year ago #

    i am at my limits, to what to suggest.
    i tried my suggested code locally in the twenty ten theme, and in a child theme; as well online in my twenty ten child theme based blog.
    no problems.
    however, each installation is unique, and the non-working might be caused by something that seems totally unrelated.

    ----
    an alternative way is to edit all occurrances of
    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
    in loop.php (copied into the child theme; occurs twice - lines 110 and 138) to include the custom field text; for instance so:

    <?php $read_more = get_post_meta($post->ID, 'cont_read', true);
    $read_more = $read_more ? $read_more : 'Continue reading';
    the_content( __( $read_more . ' <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>

    and add a section in functions.php of the child theme:
    for instance: http://wordpress.pastebin.com/8EuqBfbH

  25. billbennett
    Member
    Posted 1 year ago #

    Thanks Alchymyth. I think you've already gone well beyond the call of duty.

    I'll give this other suggestion a try later.

  26. billbennett
    Member
    Posted 1 year ago #

    This is now working, along the way I had to swap out the references to

    <?php the_content

    to

    <?php the-excerpt

    but that fixed it. Maybe this was the problem in the first place?

Topic Closed

This topic has been closed to new replies.

About this Topic