Fantasy E-books by PhenomenalPen

Creating WordPress Theme – the_excerpt or the_content Function

Be sure you’ve finished reading the first six article about Creating WordPress Theme before reading this article. Visit the links below if you haven’t.

Using WordPress the_content Function

In our theme’s index page, we used a loop to list all available posts. If we use the_content function, each time we create a post we’ll need to used the Insert Read More tag(<!–more–>). This is to avoid showing the whole content of the post in the list. The image below shows a Read more… link after a few lines of the post, that is what the Insert Read More tag do. If we don’t add a read more tag in a post, the_content function will show all the content of the post. This can make our post varies different excerpt length. And our list will looked ugly.
WordPress index Page Using the_content function

Using WordPress Excerpt Box

Instead of using the Read More tag we can also use the Excerpt box to assign a summary of a post. The form is available under the Post editor page. If you can’t see the form, check the Excerpt checkbox in the Screen Options list.

Using WordPress the_excerpt Function

If we use the_excerpt function our index page would look exactly like the image below.
Wordpress index Page Using the_excerpt function
Using this function you can see all our article summarize in the same length. The default excerpt length is 55 words and you can change its value if you want. In the image above, we make a slight chance to display a link([…]) after the excerpt.
If you want to have the same link you can add this code in your functions.php file :

function theme_excerpt_with_link($more) {
      return ' <a href="'.get_permalink().'">[...]</a>';
add_filter('excerpt_more', 'theme_excerpt_with_link');

WordPress has a lot of functions that really helps make developer’s life easy. You can choose whatever functions you like and prefer.

That’s it for now. Thank you and have a great day.

Leave a Reply

Your email address will not be published. Required fields are marked *

19 + 11 =