Home » Web

Use excerpt in index, category, tag and arhieve pages for WordPress

By: Zhiqiang Ma On: Jan 18, 2010 Views: 38 No Comment Print Email
Tags: , , ,

By default, all of the content of the post is shown in index, category, tag, archive and search pages. This is duplicate contents which may cause search engine penalty. The better way is using excerpt in index, category, tag and arhieve pages. By doing this the duplication can be avoided and the blog is optimized. After using the excerpt the blog will be much faster.

If an explicit excerpt to a post is not provided by the author, the first 55 words of the post’s content are used for excerpt. And the excerpt end with [...], which is not a “read more” link. For convenient, we may add a “read more” link at the end of the excerpt for the reader.

The method for using excerpt in WordPress
Replace the_content() function with the_excerpt() when the post is on archive (tested by is_archive()) and category (is_category()) pages and index (is_home()) page in WordPress themes. But WordPress has another function named is_singular() to determine whether this is a page or a single post. So the easiest way is use is_singular() to test whether it is the page or single post. If the function returns true, display the whole content of the post, otherwise display the excerpt.

First find the theme used under wp-content/themes. The php file for index is index.php or home.php. Try to find this sentence in the index php file:

<?php the_content(); ?>

Then replace it with:

<?php if(is_singular()) {
 the_content((__( '&raquo; Read more: ', 'default')) . the_title('', '', false));
} else {
 the_excerpt();
 _e('<div><div><a href="', 'default');
 the_permalink();
 _e('">&raquo;&raquo;&raquo; Read More of "', 'default');
 the_title();
 _e('"</a></div></div>', 'default');
} ?>

Maybe files such as archive.php should also be changed if the archives, categories and tags are displayed using different method.

It’s the same for the search pages. The only difference is the php file for search pages is search.php. Find the relevant php sentence and replace it with the codes listed above.

The is very good for SEO. After doing this the search engine will no long see a lot of duplicated contents in the blog and it will index much more pages.

Read more:

Digg del.icio.us Stumble Techorati Facebook Newsvine Reddit Twitter
Mixx LinkedIn Google Bookmark Yahoo Bookmark MySpace LiveJournal Blogger RSS feed
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.