Week Eleven (MGDP2060)
This article lists topics for week eleven of Web Design and Development III (MGDP2060).
See also Week Ten and Week Twelve.
Contents
- 1 Displaying post thumbnail (featured image)
- 2 Making a Smarter Product Page
- 3 Highlighting Products on Sale
- 4 Cleaning Out the Templates (536)
- 5 Creating single-product.php (537)
- 6 Creating content-single-product.php
- 7 Custom Fields (539)
- 8 Classifying Your Posts with Custom Taxonomies (542)
- 9 Exercises
Displaying post thumbnail (featured image)
Use this code to display the post thumbnail (featured image) for an individual post:
// check if the post has a Post Thumbnail assigned to it. if ( has_post_thumbnail() ) { the_post_thumbnail(); } the_content();
Making a Smarter Product Page
Individual product pages display unnecessary information, like author name.
Individual product pages are displayed by the single.php
template.
Highlighting Products on Sale
The "Better Home Page" example is meant for smaller websites, where the number of items is small enough to display well on the home page.
Larger websites, with a large number of items, may need some other approach.
For example a "Products on sale" or "Featured" category.
Each product belongs to both "Sofas" and "Featured" categories.
Or perhaps "Featured1", "Featured2", and "Featured3", corresponding to three columns.
Cleaning Out the Templates (536)
Individual product pages are displayed by the single.php
template.
The single.php
template gets help from another template, depending on type of content it's displaying.
Ordinary posts use the content-single.php
template to do the work.
When displaying a post that uses a custom post type, WordPress automatically looks for a template file in this form:
single-type.php
Where type is the registered name of the custom post type, in this case "product":
single-product.php
Use this template to display content for individual products.
Creating single-product.php (537)
Make a copy of single.php
. Name the copy single-product.php
.
Remove the navigation links.
Modify the get_template_part
function:
<?php get_template_part( 'content', 'single-product' ); ?>
Creating content-single-product.php
Make a copy of content-single.php
. Name the copy content-single-product.php
.
Custom Fields (539)
"Screen options" may not behave as shown in book.
Try creating new post, then setting screen options.
Classifying Your Posts with Custom Taxonomies (542)
A taxonomy is a system of classification.
WordPress provides two taxonomies: Categories and Tags.
You add custom taxonomies of your own: like Categories or Posts, but using terminology customized for a specific purpose.
See also WordPress Custom Taxonomy.