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().
the_content() and more
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:
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.
The more tag
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.