The limit-posts plugin, or the_content_limit() function as it is widely known, is a plugin/function which shortens your posts, usable when wanting to display post excerpts on the home or index page.
It is used by many premium (example: revolution from studio press) themes as a built in function.
However, it can create problems if you are trying to show an excerpt of a post in the sidebar, when you are previewing a post in a single post view.
I was struggling with it, but finally coded out a perfect solution. You can use the following code:
Instead of posting
<?php the_content_limit(100,"Read more →");?>
Use
<?php
if (is_single()) {
echo substr(get_the_content(),0,150)."... <a href=".get_permalink().">Read More →</a>";
} else {
the_content_limit(150,"Read More →");
}
?>
This function will check if you are previewing a post in a single view mode, if so, it will create a custom excerpt similar, if not the same as php the_content_limit(100, “more”).
Enjoyed this? Subscribe to the full RSS Feed!









August 27th, 2009 at 1:52 pm
great workaround! thanx a lot!