Custom ‘Read More’ text per Post for Twenty Ten

A sophisticated way to get a custom written ‘read more’ text added to your posts in the theme Twenty Ten (or its child themes).

The code builds on this article I posted earlier.

It uses the custom field with the key ‘cont_read’ to hold the custom text.

Add this code to functions.php of the theme:

/* 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>&rarr;</span>' ) {
 return $translations->translate( $cont_read . ' <span>&raquo;</span>' );
 }
 return $translation; // custom field value
 else :
 return $translation; // standard text
 endif;
 }
}
add_filter('gettext', array('Transformation_Text_Wrangler', 'reading_more'), 10, 4);

Continuous post numbers for your blog

post_numbersif you look at my blog, you may notice that all posts are numbered with a unique number – starting with 1 for the oldest post and increasing continuous for each published post.

how is it done?

with a function that is hooked to some wordpress core actions;

the function takes care of everything:

  • gets a list of all published posts
  • counts through the posts
  • adds or updates the custom field
function updateNumbers() {
/* numbering the published posts: preparation: create an array with the ID in sequence of publication date, /
/ save the number in custom field 'incr_number' of post with ID /
/ to show in post (within the loop) use <?php echo get_post_meta($post->ID,'incr_number',true); ?>
/ alchymyth 2010 */
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 0 ;
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
$counts++;
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
endforeach;
endif;
}
add_action ( 'publish_post', 'updateNumbers' );
add_action ( 'deleted_post', 'updateNumbers' );
add_action ( 'edit_post', 'updateNumbers' );

save it to functions.php of your wordpress theme.

anywhere you want to display this post number, use the following line:

<?php echo get_post_meta($post->ID,'incr_number',true); ?>

just be aware that these numbers are not unique numbers ‘for life’ as they will be reallocated when you delete a post, or when you change the post order by changing the publish date.

Remark:
to trigger the function to generate the custom fields and fill them with the numbers, you need at least to make a new post, edit one post, or delete one post.

PS: the same thing starting with number 1 for the latest post –
different custom field key, hidden.