WordPress Theme Development Tutorial Manual - Customizing Post Types and Taxonomy

Article Type

There are many different types of content in WordPress, and in the WordPress database we differentiate between them by the post_type field, so these content types are often referred to as post types.WordPress built-in data such as posts, pages, media, and so on are all a type of post.

In addition to these built-in post types, we can also register custom post types to manage various types of content.

Article types exist to assign content to the right categories - not to mix all types of content together - so it's easier to manage. In theTemplate filesIn the chapter, we mentioned that we can set up templates for each article type to display the content of the article type, this is because the content inside each article type is clearly different from the other article types, and setting up their respective template files for them makes it easier for us to display the content inside this article type in the front-end in a suitable way.

Type of article

WordPress comes with 5 post types built in out of the box and they are:

  • writings
  • web page
  • media, esp. news media
  • revised version
  • navigation menu

We can modify and delete the built-in post types above through themes or plugins, but it is not recommended to delete WordPress built-in post types for compatibility reasons.

As theme developers, the common post types we use are articles, pages, attachments and custom post types. Revision versions and navigation menus are beyond the scope of this section and will be explained in detail later in this manual.

writings

Articles are usually used to manage blog content, news information and other content that has categorized attributes and needs to be published and updated frequently.

  • Reverse chronological display, with the newest articles displayed first
  • Date and time stamped
  • utilizationCategorized directories and labelsOrganizational Articles
  • Used to create a subscription feed
  • Custom article type templates can be used

The template files used to display the articles are:

  • single.php respond in singing single-post.php
  • category.phpand all its iterations
  • tag.phpand all its iterations
  • taxonomy.phpand all its iterations
  • archive.phpand all its iterations
  • author.phpand all its iterations
  • date.phpand all its iterations
  • search.php
  • home.php
  • index.php

In addition, theme developers can display article types as needed front-page.php The

Learn more about the article template fileThe

web page

Pages are static article types outside of the normal article/subscription feed. They are characterized by:

  • Non-time dependent, no timestamp
  • Not organized using categories and/or tags
  • Can be displayed using a custom page template
  • Can be organized hierarchically - i.e. a page can be a parent/child of other pages

The template files used to display the page are:

  • page.phpand all its iterations
  • custom.phpand all its iterations
  • front-page.php
  • search.php
  • index.php

Learn more about page template filesThe

attachment (email)

Attachments are typically used to display multimedia content such as images, music, videos, etc. within content and can link to related documents. They are characterized by:

  • Contains information (such as a name or description) for adding files through the WordPress media upload system
  • Includes metadata information stored in the wp_postmeta table (including size, thumbnail, location, etc.)

The template files used to display attachments are:

  • MIME_type.php
  • attachment.php
  • single-attachment.php
  • single.php
  • index.php

Read more about the attached template file The

Custom Article Types

We can use custom post typesCreate your own article types . To ensure portability of user content, it is not recommended to create custom post types in the theme, if you need to use custom post types, it should be implemented through a plugin.

We canIn the WordPress Plugin Development ManualLearn more about Create custom post types forFor more information .

After creating a custom post type in the plugin, we can use the following template to be able to display the content of the custom post type:

  • single-{post-type}.php
  • archive-{post-type}.php
  • search.php
  • index.php

In addition, by using custom queries to buildmultiple loop, we can display custom post types in any template file.

Learn more about custom post type templates

Classification method

Categorized directories, labels and categorization methods sound similar and can be easily confused.

Below we use a sample theme created for a food recipe website to help you dive a little deeper into taxonomy, tags and custom taxonomies.

On this recipe site, we have breakfast, lunch, dinner, appetizers, soups, salads and desserts for thesecategorization. So recipes can be differentiated with these categories, but sometimes, users may need to search for something specific, such as braised pork, back to the drawing board, and so on.

Braised pork and back to the pot are atab (of a window) (computing) , they are another, more specific way of distinguishing between different kinds of recipes.

Lastly, custom taxonomies. Actually, taxonomies and tags are taxonomies, a way of organizing content. Taxonomy is a way to categorize content and data in WordPress. When we use taxonomies, we can combine similar things together. A taxonomy is the sum of these combinations. As with post types, there are some default taxonomies in WordPress, and we can also create our own.

We usually categorize recipes by categories and tags, but it would be easier for users to find content if we could add more detailed categories. For example, some users may need to find recipes by cooking time, we can create a cooking time taxonomy and add taxonomy items such as 0-30 minutes, 30 minutes to 1 hour, 1 to 2 hours, and so on. In addition, we can also categorize these recipes by cooking method, such as sautéing, baking, steaming, boiling, deep-frying, and so on.

default taxonomy

The default taxonomy in WordPress is:

  • Categorized directories: hierarchizable classifications for organizing article content
  • Tags: non-hierarchical, flat taxonomy for organizing article content
  • Article Formatting: a categorized way to create article formatting for your articles. We can create an article format in theArticle FormattingFind out more about it on the .

Taxonomy projects

Taxonomy items are items in our classification method. For example, if we have awildlifeTaxonomy where we can add items like: dogs, cats and sheep. We can add taxonomy items through the WordPress backend, or we can use the wp_insert_term() Functions add taxonomy items programmatically.

Database Architecture

Taxonomy and taxonomy items are stored in the following data tables:

  • wp_terms - store all taxonomy items
  • wp_term_taxonomy - Putting categorized items into taxonomy
  • wp_term_relationships - relates taxonomies to objects (e.g., for an article to have a certain taxonomy, certain tags))
分类型模式

templates

WordPress offers several different template hierarchies for taxonomies, tags or custom taxonomies. For more detailed information on their structure and usage, see the "WordPressCategorized templates" page.

Customized Taxonomy

We can create new taxonomies in WordPress. For example, we may need to create book review sites in theauthor category, or create a movie site on theactor or actress Classification. As with custom post types , theIt is recommended to put this feature in a plugin . To ensure that when a user changes the theme, its content will remain in the plugin.

We can read about it in the plugin developer's manual on theCreate customized categoriesFor more information on the

We offer WordPress Themes and Plugins Custom Development Services

This site has long undertaken WordPress themes, plugins, WooCommerce-based store mall development business. We have 10 years of experience in WordPress development, if you want to Developing Websites with WordPress, please contact WeChat: iwillhappy1314 or email: amos@wpcio.com for inquiries.

发表回复

Your email address will not be published. 必填项已用 * 标注

*