WordPress ‘Read More’ link wasn’t working for post excerpts.

After battling for many hours to make my posts excerpts when they are listed and full posts when they are clicked, I finally got it all working.  The first problem was the way that the the single.php and the post.php pages were written.  Any attempt to add the excerpt function to the posts was shortening the posts everywhere.  The single.php file, which is loaded when a post is clicked in WordPress, was calling the post.php file.  The post.php file is called any where a post is needed to be displayed.  So the two needed to be unique.

The post.php file is where I wanted to use the excerpt function as below.

<?php /* Global Post file. */ ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
<div class="post-content">
<div class="post-title">
<h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php _e('Permanent Link to', 'cp'); ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
</div>
<div class="post-meta">
<span class="post-meta-info"><?php the_time( __('F jS, Y', 'cp') ); ?> · <?php the_author_posts_link(); ?> · <?php the_category(', ') ?></span>
<span class="post-meta-comments"><?php edit_post_link(__('Edit', 'cp'), '', ' · '); ?><?php comments_popup_link(__('No comments', 'cp'), __('One comment', 'cp'), '% '.__('comments', 'cp') ); ?></span>
<span class="post-meta-info"><?php the_tags(' - Tags: ', ', ', ''); ?></span>
</div>
<?php if( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?>
<div>
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="post-entry">
<?php the_excerpt( '<div class="post-read-more">' . __("Continue reading ¬Ľ", "cp") . '</div>' ); ?>
</div>
<?php if ( is_single() or is_page() ) { wp_link_pages(array('before' => '<p class="post-pages"><strong>' . __('Pages:', 'cp') . '</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); } ?>
<div class="clear"></div>
</div><!--#END post-content -->
</div><!-- #END post -->

The single.php file is where I wanted to read all the content and not simply include the post.php file.  I did this as follows.
<?php get_header(); ?>
<div id="content" class="col-full">
<div id="main" class="col-left">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
<div class="post-content">
<div class="post-title">
<h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php _e('Permanent Link to', 'cp'); ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
</div>
<div class="post-meta">
<span class="post-meta-info"><?php the_time( __('F jS, Y', 'cp') ); ?> · <?php the_author_posts_link(); ?> · <?php the_category(', ') ?></span>
<span class="post-meta-comments"><?php edit_post_link(__('Edit', 'cp'), '', ' · '); ?><?php comments_popup_link(__('No comments', 'cp'), __('One comment', 'cp'), '% '.__('comments', 'cp') ); ?></span>
<span class="post-meta-info"><?php the_tags(' - Tags: ', ', ', ''); ?></span>
</div>
<?php if( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?>
<div>
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="post-entry">
<?php the_content( '<div class="post-read-more">' . __("Continue reading ¬Ľ", "cp") . '</div>' ); ?>
</div>
<?php if ( is_single() or is_page() ) { wp_link_pages(array('before' => '<p class="post-pages"><strong>' . __('Pages:', 'cp') . '</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); } ?>
<div class="clear"></div>
</div><!--#END post-content -->
</div><!-- #END post -->
</div><!-- #END main -->
<?php get_sidebar(); ?>
</div><!-- #END content -->
<?php get_footer(); ?>

This effectively gave the single.php its own post style.

The second problem I had was the [...] that is automatically inserted when the excerpt function is called in post.php.¬† I wanted that to say “read more…” and be an actual link to the article.¬† Since this was not built into my theme I had to ad the following code to my functions.php file.

//ellipsis
function excerpt_ellipse($text) {
return str_replace('[...]', ' <a href="'.get_permalink().'">Read more...</a>', $text); }
add_filter('the_excerpt', 'excerpt_ellipse');

Though I don’t fully understand the inner workings of the WordPress core, I found many versions of this solution on other blogs and the WordPress Codex.

Just another lesson in ask Google and keep at it.  I had almost given up before this little break through, but as you can see on this site and many others, the excerpt teaser for a list of articles is very handy.


Join the discussion

Email addresses will not be published.
Comments will not be displayed until approved by an admin