7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 22Length: 2.8 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

3.14 The 404 and Search Pages

Hey, welcome back. So as you can see we only have just a few files to write to complete the framework. And the next on the list is the 404 page. So what is 404? Well if, if you go to the website and do like a slash. This, you get a Not Found message. So let's quickly create a 404.php to address that. Okay, so we start with the header, get_header, and then the footer. Now, this won't need a sidebar because it needs to be different than all the other pages. So for that we're going to create a class container dash 404 and inside we're going to have an h1 that says php we're going to echo translatable string, says Error 404. Nothing found. And then the text domain, and under that, we're gonna do a paragraph with a bit more explaining. So again, we're gonna echo, so it looks like nothing was found here, maybe try a search, alpha, and to complement this we'll do php get_search_form. Okay, so now if we refresh, we won't see any change, and here's why. By default, if WordPress will not find the page you are looking for, it's gonna search for the 404 web page. But, there are cases when the web server has this problem before WordPress is aware of it. And to make sure WordPress knows about this and knows where to send the user, you need to edit the .ht axis file. Well, I'm not going to do that right now, but I will link you to a page which explains this whole process in detail. So check out these lesson notes. Now, the next item on the list is the search form. And I'm just gonna add a search widget, so you can see what we're dealing with. I'm gonna add it to the main sidebar. Actually, no, let's add it to the footer. Okay, so it seems we already have one in the footer, so I'm gonna delete that. Refresh. Now let's scroll all the way down, and this is the search form. Let's search for. Template for example. Search, and it's going to give me a list of posts that have the word template inside their title. So this is actually very similar to an archive page. So I'm gonna open up, let's see, category, I'm gonna copy the content here. Gonna create a new file called search.php. Gonna paste that in and let's see search.php, the template for displaying search. Results, and we have the header. We have the main content. If we have posts we're going to display this header right here with an h1 that's gonna say search. Results for are sent s and then instead of this I'm gonna say get search query. And this will give me the word or keyword that I search for. And then we don't need this bit. While have posts and the rest of the page is the same. So now if I refresh I get search results for template. And I can change it, I can search for, I don't know, this bit. And it's gonna give me nothing found. Or I can search for something else like comments. Now that's gonna give me template comments, comments disabled, and so on. Okay, and that's basically it for this lesson. Now, let's take a look at the road map here. So category 404, okay. So next is the full width template and also the contact template. These are like custom page templates that you can use on your pages. And that's coming up in the next lesson.

Back to the top