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?
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?
Look at the function.php file, line 241. The wording can be changed there.
Far better to put the new function when u find it in functions.php in yr Child Theme IMHO. Never hack core files.
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');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.
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.
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 ;)
/* 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">→</span>' ) {
return $translations->translate( $cont_read . ' <span class="meta-nav">»</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
Very cool. Thanks ;)
Would it be possible to pull the text for alternatives to "Continue reading" from a custom field?
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 );
I'm sorry - I tried reading the code, but couldn't figure it out. (I'm not really a programmer at all).
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 → → into »
»
did you get it to work?
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 :-)
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.
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?
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">→</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->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">→</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.
Thanks
I appreciate this, I also hope it will help others.
Functions.php is saved at: http://wordpress.pastebin.com/wPVm5Q9M
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.
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
Definitely not a plug in problem...just deactivated and nothing changed
Moving the code to the parent functions.php didn't seem to make any difference.
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">→</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">→</span>', 'twentyten' ) ); ?>
and add a section in functions.php of the child theme:
for instance: http://wordpress.pastebin.com/8EuqBfbH
Thanks Alchymyth. I think you've already gone well beyond the call of duty.
I'll give this other suggestion a try later.
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?
This topic has been closed to new replies.