Time for action – creating a custom page.php template file

We create our page.php template file by copying index.php and making some adjustments.

  1. Create a new file called page.php.
  2. Open index.php, copy its entire contents, and paste them into page.php.
  3. In page.php, find the code to display the This Month: heading and delete it:
    <h2 class="thisMonth embossed" style="color:#fff;">This Month:</h2>
  4. Now find the code to display the author metadata and delete that:
    <p class="entry-meta">by <?php the_author_meta('first_name'), ?> <?php the_author_meta('last_name'), ?> in <?php the_category(", ") ?></p>
  5. Next, find the code for the Read more link and the comments count and delete that:
    <p class="left"><a class="more" href="<?php the_permalink() ?>">Read more &raquo;</a></p>
    <p class="right"><a class="comments-count" href="<?php the_permalink() ?>"><?php comments_number("0", "1", '%') ?></a></p>
  6. Finally, save page.php and refresh your browser.

What just happened?

We created a new file called page.php to display static pages, and edited it to remove any content we don't need on those pages.

Now the About us page looks like the screenshot below:

What just happened?

Much better—the metadata has gone, as well as the Read more link, the comments count, and the confusing heading.

In Chapter 4, Advanced Theme Features, we'll look at doing more with page templates, for example, creating a template that doesn't display a sidebar.

Pop Quiz – questions about WordPress theme structure

Q1. According to the WordPress hierarchy, which of the following is true and which is false?

  1. page.php trumps index.php when viewing a static page
  2. archive.php trumps category.php when viewing a category archive
  3. single.php trumps index.php when viewing a static page

Q2. What does the header.php file contain?

  1. The <head> tag and its contents
  2. The <header> tag and its contents, taken from the theme design
  3. Everything from the opening DOCTYPE to the end of the <header> tag

Q3. Which files normally include widgets?

  1. footer.php
  2. sidebar.php
  3. header.php
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.23