I have a problem with displaying some content on my homepage. First i'm going to explain my problem. I have a page with all my blog posts on it (use of excerpt function). When you click on a read more link on the blog posts page, you get the whole article. On my homepage I want to show the 3 latest posts. I already have the top 3 off the posts. (with the use of the excerpt function) but these teasers or to long. There is to much text. I don't want to make it shorter because when I do this, the page with all the blogposts is also going to change. I was thinking to use the custom fields in the blog posts. Then I can make an extra field for the teaser content on the homepage? Is this the right solution or is there something else?
I think what your trying to ask is.
See this similar question on StackOverflow
Custom Fields are perfect for this when you want not different excerpt lenght, but also different excerpt content.
Following code will add additional TinyMCE editor to the Edit Post admin page so you can write formatted excerpt specially for your front page. Excerpt will be stored in
Put it to your
And get your excerpt inside front page loop:
No need for custom fields. WordPress already has this - the Excerpt meta box. On WP3.2+ this is usually hidden by default. To display this text box, open the Screen Options found in the top right corner of the post edit screen, then look for the excerpt checkbox and enable it. You should now see an Excerpt text box somewhere below the content editor. Write your custom excerpt here.
By using a custom field, you will be able to use a custom text instead of just a truncated text, which is best for SEO : you could write real teasers. But, it's also more work when publishing.
If there is not point, you you just need to change the lenght of the except, I would use one built-in functions of WP which is
I would propose this structure :
So you could have an specificly written excerpt using the dedicated field on a post, cut to a specific number for the first three posts, and the automatic excerpt for the rest of the loop.
Hope this helps. Regards
I changed the original code proposition because
LAST EDIT Referring to the codex, the_excerpt() always returns something:
If you do not provide an explicit excerpt to a post (in the post editor's optional excerpt field), it will display an automatic excerpt which refers to the first 55 words of the post's content.
In practise: When you post a new post, I assume there is always content? Why should we blog otherwise? So this is the code I will maybe use:
EDIT AGAIN I have try to introduce the idea of having the first three post having a different excerpt from the rest of the loop. We could have use offset, too.