Post Type – Developing WordPress Themes Part 4

 Post Type – Developing WordPress Themes Part 4

There are many different Post Type in WordPress. These content types are usually described as post types, which can be a bit confusing as they refer to all the different types of content in WordPress. For example, an Post is a specific post type, and so is a page.

Internally, all post types are stored in the same place – in the wp_posts database table – but are differentiated between them by a database column called post_type.

In addition to the default Post type , you can also create custom post types .

The template files page briefly mentioned that different post types are served by different template files. Since the whole purpose of a template file is to display content in a certain way, the purpose of post types is to categorize the type of content you are dealing with. In general, certain types of posts are associated with specific template files.

# Default Post


There are five default post types that are readily available to users or used internally by your WordPress installation:

  • Post (Post Type: ‘post’)
  • Page (Post Type: ‘page’)
  • Attachment (Post Type: ‘attachment’)
  • Revision (Post Type: ‘revision’)
  • Navigation menu (Post Type: ‘nav_menu_item’)

The above post types can be modified and removed by a plugin or theme, but it is not recommended to remove the built-in functionality of a widely distributed plugin or theme.

The most common post types that you will interact with as a theme developer are post types, page, attachments, and custom post types. Explanation of checklist post types and navigation is outside the scope of this handbook. However, it is important to note that you will be interacting with and creating the functionality of the navigation menus, and this will be detailed later in this handbook.

Post Type

Posts are used in the blog.

  • Displayed in reverse sequential order by time, with the most recent post first
  • It has a date and time stamp
  • Default ratings for categories and tags may apply
  • used to create feed

Template files that display the post type are:

  • single.php –  single-post.php
  • category.php 
  • tag.php 
  • taxonomy.php
  • archive.php 
  • author.php 
  • date.php
  • search.php
  • home.php
  • index.php

page # page

Pages is a fixed post type, outside of the normal blog feed/flow. Its features are:

Template files that display the page post type are:

  • page.php 
  • $custom.php 
  • front-page.php
  • search.php
  • index.php

Attached

Attachments are commonly used to display images or media in content, and can also be used to link to related files. Its features are:

Contains information (such as name or description) about files uploaded through the media upload system
For images, this includes metadata information stored in the wp_postmeta table (including size, thumbnails, location, etc.)
Template files that display the attachment post type she:

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

Custom Post Type

With Custom Post Types , you can create your own post type.

While you generally won’t develop custom post types into your template, you may want to code ways to display custom post types generated by a plugin. The following templates can display custom post types:

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

Additionally, theme developers can display custom post types in any template file, often using multiple loops.