Week Ten (MGDP2060)
This article lists topics for Week Ten of Web Design and Development III (MGDP2060).
See also Week Nine and Week Eleven.
Contents
- 1 In the News
- 2 Categories
- 3 Creating Custom Category Pages
- 4 Adding a Category Description
- 5 Finding the Right Template File
- 6 Some Themes don't have category.php
- 7 Make backups
- 8 Changing a Category Page's Title (523)
- 9 Adding Extra Information
- 10 Reordering Posts
- 11 Removing Post Footers
- 12 Different Category Pages for Different Categories
- 13 Building a Better Home Page
- 14 Cleaning Out the Template
- 15 Adding Text
- 16 Creating Links
- 17 The Multi-Column Effect
- 18 Comparing get_posts() and query_posts()
- 19 Extracting information from a Post
- 20 Making a Smarter Product Page
- 21 Highlighting Products on Sale
- 22 Cleaning Out the Templates (536)
- 23 Creating single-product.php (537)
- 24 Creating content-single-product.php
- 25 Adding a Category Description
- 26 Topic summary
- 27 Exercises
In the News
- 2016 Dyn cyberattack - executed through a botnet consisting of a large number of Internet-connected devices—such as printers, cameras, residential gateways and baby monitors—that had been infected with the Mirai malware.
- Firefox disables loophole that allows sites to track users via battery status - researchers discovered that it was easy to abuse the feature to track browsing on the internet.
Categories
The textbook example expects you to create three categories, each representing a product line:
- Sofas
- Chairs
- Tables
Creating Custom Category Pages
A Custom Category Page -- also known as a Category Archive Page -- displays Posts which belong a specific WordPress Category.
This is useful when working with Custom Post Types. For example, the "Products" custom post type has categories for product lines such as Sofas.
Features you can control when designing a category archive page:
- Title
- Description
- Products in alphabetical order, by title (as opposed to chronological order, like standard Posts)
Note that Custom post types do not display in standard Templates.
Adding a Category Description
You can add a customized description for any Category using the WordPress Dashboard.
Some Themes do not display the description. You must edit the Template file(s) yourself.
Finding the Right Template File
Hierarchy of Template files relating to Categories:
-
category-slug.php
-
category-id.php
-
category.php
-
archive.php
-
index.php
See WordPress Category Template and WordPress Template hierarchy.
Some Themes don't have category.php
Many Themes have a category.php
file, but some don't.
In a Theme without category.php
, the archive.php
file may be complex, providing different output based on Category, Tag, Author, or Date.
Make backups
Make backups.
Changing a Category Page's Title (523)
Edit the category.php
file as shown in the textbook.
Note the printf()
and single_cat_title()
functions.
Adding Extra Information
Edit the category.php
file as shown in the textbook.
Also add a style rule named #WarrantyBox
.
Reordering Posts
Add the query_posts()
function as shown in the textbook.
Note the orderby
and order
parameters.
Find and remove markup as shown in the textbook.
Different Category Pages for Different Categories
For Templates which display a specific category, use Template files named like this:
category-sofas.php
In this example, "sofas" is the slug associated with the "Sofas" category.
The slug is all lower case. If the category has two or more words separated by spaces, the slug uses hyphens rather than spaces.
Building a Better Home Page
An improved home page might display links to specific products.
Cleaning Out the Template
In the index.php
template, delete the Loop as shown in the textbook.
Adding Text
Add text to index.php
as shown in the textbook.
Creating Links
Add markup and PHP as shown in the textbook.
The Multi-Column Effect
Use CSS class rules with the float
property.
Comparing get_posts() and query_posts()
The get_posts()
function retrieves a set WordPress Posts.
get_posts()
is usually followed by the WordPress Loop.
The query_posts()
function also retrieves a set WordPress Posts.
query_posts()
works inside the WordPress Loop.
Extracting information from a Post
..
Making a Smarter Product Page
..
Highlighting Products on Sale
..
Cleaning Out the Templates (536)
..
Creating single-product.php (537)
..
Creating content-single-product.php
..
Adding a Category Description
..