Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
On index pages, we have three main options when it comes to how we want to display the content of the post. We can display excerpts, which are either custom excerpts defined by the author, or the first 55 words of an article, or we can display the full content. And if we display the full content, the author can choose to add the more tag anywhere within the content and this will terminate the content at that point and provide a read more link so that the visitor can see an excerpt of the post at the top and then jump though the full article.
Now we have to make the decision how we want to display regular content in our index pages. This'll be the default settings for all our index pages and then later on, we'll look at how we can make exceptions. Looking at the front page or any of index pages right now, you'll see we're currently displaying the full content. Meaning, if you get through a very long post, like this HTML tags and formatting post, you'll be scrolling for quite a long time before you get to the next post. So, while this is great if you're reading that post alone, it's not ideal for index pages.
So, what we want to do is display just the excerpt on all our index pages and that can be toggled on and off with a simple function. If we go to the content.php template and we scroll down until we find the content section, you'll see, by default, underscores ships with a conditional statement that decides what type of content is displayed as the main content. It starts out by checking whether or not this is a search page, and if it's a search page, it displays the entry summary div and then the excerpt.
If it's any other page, it displays the entry content and then it uses the function the_content, to display the content and within that function, there's a variable that says, if the content is terminated with the more class display continue reading, and then an arrow, so that people can click on it to go to the full post. In my design, I want to only show the excerpt on all my pages except for the first post of the front page. So, I'm going to change all this. I'll remove the conditional statement first, so I'll take out the if statement and the else statement.
And then also take out the end if statement at the bottom here. Then I'll do some general clean up. Then I'll go to the entry content section and change the function from the content to just the excerpts, which will display the excerpt. And then, finally, I'm going to remove this link pages function. Now I'll save content.php and go and reload my front page. And you'll see a dramatic difference. Now each of my posts are displayed just with a title, the meta content, and the excerpt for that post.
And when the content is longer than 55 words, you get this square bracket with an ellipsis inside shows there's more content to come. Of course, now that I've truncated the content in the index pages, I need to provide a link on the bottom to point people to the full content and that's next.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.