Monday, April 20, 2015

custom content in WordPress and show you how to create that content.

  • I’ll look at the three types of custom content in WordPress
  • Custom post types
  • Custom taxonomies
  • Custom fields.
  • Custom Post Types

    WordPress comes with a set of post types available to you by default. These are:
    • Posts
    • Pages
    • Attachments
    • Navigation menu items
    • Revisions
    • Links (if you’re using the blogroll feature)
    • You can also create your own custom post types to store content which doesn’t fit into any of the above categories. Examples might include products in an e-commerce site or events in a listings site. If you’ve ever used a plugin to create a store, event listing or any other kind of unique content, the chances are you’ve created custom post types without even knowing it.
      Plenty of our plugins use custom post types, for example:
      There are plenty more examples, but this gives you an idea of the uses of custom post types.
      It’s important to remember that custom post types are not posts. They don’t have any direct relation to posts and you should think of them separately. You can set up (or register) your custom post types to behave like posts or to behave like pages: it’s up to you. If they’re set up like posts you’ll be able to display archive pages of them while if they’re like pages they’ll be hierarchical. Most custom post types are configured to behave like posts but that doesn’t mean yours have to be.
    • ************************************************************************
    • What is a taxonomy?

A taxonomy is a way to group things together.
  1. a classification of organisms into groups based on similarities of structure or origin etc
For example, you have a custom post type called Books. Even though you can use categories, you may not want to mix the two because they are used differently. You can register a new custom taxonomy called Topics. You can add topic terms like: Adventure, Romance, Non-Fiction, etc. This would allow you and your users to sort your books by each topic. 

Custom Taxonomies

Like custom post types, custom taxonomies add to the taxonomies that are already provided with WordPress. These are:
  • Categories
  • Tags
  • Post formats
  • Link categories (which apply to links in the blogroll if you’re using it)
You can also create your own custom taxonomies to organise your content more effectively. It’s important to remember that a custom taxonomy is not a category and has no relationship to categories: instead, ‘category’ is just one of the taxonomies used by WordPress.
Sometimes using the inbuilt categories will give you everything you need to sort your content, for example if you need to introduce a hierarchical category structure. But sometimes this won’t be enough, especially if you want to be able to display posts using more than one taxonomy, or if you’re using a custom post type and want to use a separate taxonomy for it.
Examples include:
  • On an e-commerce site, product taxonomies – possibly multiple ones such as colour, size and fabric for a clothing store.
  • On an events listings site, taxonomies for event type, venues and more.
  • On a knowledgebase, taxonomies to sort data in a crosscutting way: for example if it’s a web development knowledgebase you might use taxonomies for programming languages, level of difficulty and platforms.
Again our plugins make use of custom taxonomies: for example in MarketPress there are product categories and product tags, which are separate from the categories and tags for blog posts; in CoursePress you have course categories; and in Support System there are taxonomies for ticket types and FAQ categories.
Before deciding if you need to register a custom taxonomy, you need to ask yourself if the existing category system will do what you need. If all you need is to be able to add a hierarchy to your categories, you can already do this.
categories
So if I was developing a training site (for example) and wanted to use categories to sort posts by the skill or knowledge being taught, I might use hierarchical categories as shown in this screenshot. You can see here that I’ve got three top level categories: management development, personal development and technical skills, with everything else beneath these at the next level down.
categories-and-taxonomy
But what if things got a bit more complicated? Let’s say I wanted to add a series of posts on communicating with your team.
It would make things easier if I could separate out the fact that these posts are for managers but also deal with communication skills. So maybe I could add a taxonomy for the audience, and use this to identify posts for managers instead of having management development as a category, I could create a new taxonomy for audiences. That way I can identify multiple topics and multiple audience groups for each post.
I’ll show you how to create a taxonomy like this in the next part of this series: once you’ve done it, you’ll be able to choose from both categories and audience groups in the post editing screen, as shown in the screenshot.
**********************************************************************

Custom Fields

The third type of custom content is the custom field, also referred to as post metadata.
A custom field consists of two elements which you can see and edit in the post editing screen: the key and the value. You can use the same key again and again for multiple posts, but each will have a unique value. WordPress also gives each custom field you create its own unique ID, which means that each custom field for each post is unique even if they have the same key and value.
This is different from custom taxonomies: although you can choose from an existing key when creating a custom field, you can’t select from existing values you’ve used before. Generally this means that taxonomies are better for sorting and categorising data.
Note: Some plugins will give you the option to choose the value of a custom field from a dropdown box, but this will use a custom metabox created by the plugin in the post editing screen, instead of the standard custom fields interface provided by WordPress.
However there are some cases in which using a custom field can be useful to sort data, for example if you want to store numerical data. In an e-commerce site you don’t want to create a taxonomy for every possible price: instead you’d insert this in a custom field. You could then use this data to allow customers to identify products with a price below $20.00 for example, or to sort by price.
You can also use custom fields to store non-numerical data, meaning you can store and display similar data between posts and display it separately from the body of the post. For example in a jobs listing site you might use custom fields to store the location, salary and working hours for a vacancy.
This is what the Jobs & Experts plugin does: it uses a combination of custom fields (referred to as ‘Job Meta’) and taxonomies (‘Category and Skill’) to sort data:
jobs&experts-metadata
Once you’ve added this data, visitors to your jobs site will be able to sort jobs by budget, display only those jobs which are still open and see the contact email and completion date for each job displayed prominently. A taxonomy is used for skills so that archive pages for each of these can be displayed.
You’ll learn how to create your own custom fields in the next part of this series: in this post, we’ll move on to creating custom post types.

1 comment:

  1. This guide is a must-read for anyone looking to master custom content creation in WordPress! For seamless hosting solutions that enhance your WordPress experience, check out DVHosting.

    ReplyDelete