Controlling how your posts display throughout your site is easily done with a choice of 2 template tags and a bit of additional code. Full posts are displayed by using the_content() and excerpts are displayed by using the_excerpt().
This tag will display a full post unless you use the more tag. The more tag is set whilst writing the post. You can click a button on your post area’s toolbar or, if you’re not using the richtext editor then you can also type it in. The more tag looks like:
<!--more-->
Note, there are no spaces in this piece of code. By using this tag in your post you will cut off your post where you specify the tag on the front page, category and archive pages. It will not have any effect on the single post page however. It will also add a ‘Read more…’ link at the cut off point of the post.
the_content() tag can accept 3 parameters, however I’ll only explain the first parameter as this is the most likely to be used. The tag can accept the anchor text to display when the more tag is used therefore overriding the ‘Read more…’ anchor text. For accessibility and SEO purposes I highly recommend a unique anchor text for each more link. A suitable value for this parameter is therefore
<?php the_content("Continue reading " . the_title('', '', false)); ?>
This would then give you a more link for this post of Continue reading Control Your Content. (Note, the_title() template tag accepts a third parameter of ‘false’. This prevents the_title() from automatically printing the title to screen and instead returns it as a variable for use within the code).
This tag will automatically strip out any html coding and then display the first 55 words of your post followed by a [...] at the end of the post, which is not linked to the rest of the post. It should only be used on the front page, category and archive pages, and in my opinion, whilst it saves having to remember to use the more tag, it removes some of the flexibility of what is displayed. We do have an additional box on the Write a Post page, where you can specify your own excerpt which does give you back a bit of the flexibility.
Well, it’s not really a tag but a comment. This can be handy to allow you to override the ‘Read more…’ text by accepting a piece of text within the tag. This is useful if you want to change the output of the standard anchor text as maybe specified in the_content() tag within your template. For example:
<!--more Your Anchor Text here-->
Again, there should be no space before the word ‘more’ but then you can insert your Anchor text after it and this will then be used as the anchor text of the read more link.
Next week I’ll show you how you can take these tags and use them with some basic PHP to create different theme looks.
Author comments are in a darker gray color for you to easily identify the posts author in the comments
Comments are closed since this post is older than 30 days. However, you can continue this discussion in our popular Blogging Forums
Thanks for the coding tips. Being a blogger (but not a web developer) I’ve spent way too much time worrying about formatting instead of writing. Thanks again!
Great post..thanks.
Great tip indeed. I wonder why a plug-in (the excerpt reloaded) was developed anyway since it looks like the_excerpt() is doing a great job.
I’m guessing the Excerpt Reloaded doesn’t strip the tags out of the excerpt, and possibly allows you to define how many words to display (whereas the_excerpt() tag just does 55). I know Kevin uses an excerpt plugin of some kind on the front page of this site which does do a good job.
Personally I wouldn’t bother with the_excerpt() tag and use the more tag as you have a greater flexibility with it, that’s if you want all of the posts to look the same on the front page. In Part 2 I’ll go more into how you can use these two tags together
Good post, but not all templates support this syntax
unfortunately…
Any template for WordPress can support this syntax. If the template doesn’t have the tag in it that you want to be using, this post should have effectively covered how to change it.
If you’ve got a problem changing your template, post the code up (using the code tags) or post it up in the forums and we’ll try and help you out.
thx, but I made myself all. Soory, my english is terrible) I’m from Russia, always read your blog)
No problem FRiK, but if you’re running WordPress then the above tags and everything I personally write on BloggingTips will work in WordPress, so if you need a hand with anything post up in the forums and I’ll be happy to help you out.
If you’re not running WordPress then help is still available in the forums
OK