Class on Thursday 4.4.13

Today we are going to talk briefly about Assignment 4 (everyone who turned one in should have a score and feedback) and we are going to introduce some new pages that are relatively straightforward.

New Pages

Review page.php

This is the page that shows a static page on the site. It’s like index.php but you don’t need the if(have_posts()), just the while(have_posts()) part.

To give us some flexibility we’ll pair that with content-page.php. This is like the way we paired

  • single.php
  • content-single.php

You will need to make sure you call

<?php get_template_part('content', 'page'); ?> 

inside of page.php. And then create content-page.php, which for simple purposes can be like content-single.php (pages can have comments too).


To do the search you need two things
1. The search form
2. The search results page

The Search Form

Showing the search form is pretty easy. There is a template tag for that.

<?php get_search_form(); ?> 

Put that were you want the search form to appear. If you want it on every page you’ll have to put it in header.php or sidebar.php or footer.php or else make sure it’s in all of the content pages ( which is more locations to remember).

The Search Results

This page shows the search results. Basically it’s a page that has the search results in it. You can copy page.php and rename it as search.php. Then you change the header of the page so it tells people they will see search results:

<header class="page-header"> 
    <h1 class ="page-title"> Search Results </ h1 > 
        You searched for < br / > 
        <span> <?php the_search_query(); ?> </span> 

This is sligly different from the book which just has what I put in the h2 inside of the h1

404 page

When someone requests a web page that doesn’t exist on the server it sends back a 404 result (for a normal page it sends back 200 to say the page is there). In WordPress you can have it show a custom page you design instead of some plain text in the browser.

It’s not difficult to do. Because the 404 page can be the same every time you can just put out some static content that says “This page is not found” or whatever you want. Add in the get_header(), get_sidebar(), get_footer() and you have a page. Many people also add in a link to search here so people can search the site for what they were looking for.

<?php get_header(); ?> 
<h1>404 Page Not Found</h1> 
<p>Sorry, we couldn't find the page you were looking for. Perhaps try searching &hellip; </p> 
<?php get_search_form() ?> 
<?php get_sidebar(); ?> 
<?php get_footer(); ?> 

Leave a Reply