7 days of unlimited WordPress themes, plugins & graphics - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 15Length: 1.6 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.1 Create a Single Blog Entry Template

Hi, and welcome back to Build a Blog, with Craft CMS. So far we don't have any templates set up to show our single entry, so when a user clicks on a link to read a whole post, there's nothing there. So, we're gonna fix that in this lesson. The first thing that we need to do is make sure that we create the correctly named template in the correct location. So what we're gonna do is just refresh our memory, go in to the Settings of our site, go into Sections, and then go into our Blog section. Now we wanna scroll down and see what we have entered here, as the template that we wanna use for our entries. So here you can see that we've said we're gonna have a template in the blog folder and that is gonna be named _entry. So now let's go ahead and create that template file. So we're gonna need a new folder. We're gonna call it blog. And then in here, we'll create a new HTML document named _entry. And by the way, you no longer need this news folder that was there before for the default craft installation. So you can delete that. Now we'll open up our entry template file for editing. This template file is gonna have a few things in common with both the index file that we've been working on, and the entry teaser. We're gonna reuse some of this HTML. So start by just copying all the code from your index HTML template and pasting it in. We want all of this except what's inside the main element. So that's gonna give us the extension of our layout template. And it's gonna give us the block that gets loaded into the layout template, as well as the main element that we need. Then you can also copy all the code from the entry teaser and paste that in there, and we're gonna reuse a lot of what is in here. So if you just go through, it'll sort of make sense to you what you need to retain. Yes, we wanna display a featured image if there is one. We also wanna display the date which is done with this card. We wanna keep our heading but we no longer need it to link. So we're just gonna get rid of the link HTML. And we'll change that to an H1 tag. We also no longer need a teaser and we don't need to read more link, so we'll get rid of those, and we'll just replace that with entry.body. And that is actually all we need to do to make our entry template work. So if we go back to our front end. Now we have our fully functional single entry template. And if we look at another entry that has a featured image, it'll be the same thing with this one. We have our image coming in correctly, because we've loaded that partial into this template file. We have a date, we have a unlinked H1 version of our title. And then rather than a single paragraph, we have the full article in here. Then we've got our categories down below, and obviously there's no need for a read more link in here. So when you're looking at a single entry, all you need to do is make sure that the place you create the template matches up with what you have here, for the section in question. Next up, we need to make sure that when you click on the link here, to go through and look at the page for a particular category, we have something showing up there. We wanna make sure that we list all of the entries for any given category, and we wanna have them display in the same way that we're showing posts on our home page. So we're gonna go through how to do that in the next lesson. I'll see you there.

Back to the top