I recently felt the need to show only excerpts on most of my wordpress pages, such as the wordpress homepage, when browsing through the archives, etc. Any page that wasn’t the immediate blog post, I wanted to just display the excerpt (which is really useful if you’re like me and write gigantic posts).
I did a Google search to see what other people had done, and I was able to find a forum post which explained it, however their post was incorrect and would cause the actual content pages to just show excerpts as well, thereby making it impossible to view all posts. So, using my knowledge of the is_singular() function, I was able to come up with the following solution.
Go to your current theme folder, and modify the index page, and find the line in the file that has the the_content() function call, and replace it with the following:
/blog/wp-content/themes/{theme-name}/index.php
<?php
if (is_singular()) {
the_content('<p><b>Continue Reading »</b></p>');
} else {
the_excerpt('<p><b>Continue Reading »</b></p>');
}
?>
What this translates to: The if statement will see if the page is a singular page (meaning only one post on the page, aka directly viewing the post via the permalink). If we’re on this page, we will show all of the content, otherwise we will show the excerpt for the content (and since we’re in a loop it will go through and show all of the other excerpts).
Tags: Wordpress
Category: Uncategorized









