Difference between revisions of "Week Ten (MGDP2060)"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(Comparing get_posts() and query_posts())
Line 112: Line 112:
 
== Comparing get_posts() and query_posts() ==
 
== Comparing get_posts() and query_posts() ==
  
..
+
The <code>get_posts()</code> function retrieves a set WordPress Posts.
 +
 
 +
<code>get_posts()</code> is usually followed by the [[WordPress Loop]].
 +
 
 +
The <code>query_posts()</code> function also retrieves a set WordPress Posts.
 +
 
 +
<code>query_posts()</code> works inside the [[WordPress Loop]].
  
 
== Extracting information from a Post ==
 
== Extracting information from a Post ==

Revision as of 20:36, 2 November 2016

This article lists topics for Week Ten of Web Design and Development III (MGDP2060).

See also Week Nine and Week Eleven.

In the News

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.

Removing Post Footers

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

..

Topic summary

Exercises

See Week Ten Exercises (MGDP2060).