How to Preview and Activate WordPress.com Themes
How to Upload a New WordPress Plugin
How to Add Widgets to Your WordPress.com Blog Sidebar

Example of WordPress Custom Post Types

After you complete the steps to create a basic custom post type to your WordPress website, it’s added to the left navigation menu in the Dashboard, as shown. In this example, the custom post type is called "Generic Content."

image0.jpg

You add and publish new content using the new custom post type just as you would when you write and publish blog posts. The published content isn’t added to the chronological listing of blog posts, but is instead treated as separate content, just like static pages.

View the permalink for the custom post type, and you see that it adopts the post type name, Generic Content, and uses it as part of the permalink structure. The permalink looks like http://yourdomain.com/generic-content/new-article.

Here is a real-life example from the No Rules Theatre site. This site uses a Shows custom post type to create custom content for the shows that the theatre produces each season.

// ADD CUSTOM POST TYPE: SHOWS
add_action( 'init', 'create_my_post_types' );
function create_my_post_types() {
             register_post_type( 'shows',
             array(
             'labels' => array(
             'name' => __( 'Shows' ),
             'singular_name' => __( 'Show' ),
             'add_new' => __( 'Add New Show' ),
             'add_new_item' => __( 'Add New Show' ),
 
 
             'edit' => __( 'Edit' ),
             'edit_item' => __( 'Edit Show' ),
             'new_item' => __( 'New Show' ),
             'view' => __( 'View Show' ),
             'view_item' => __( 'View Show' ),
             'search_items' => __( 'Search Shows' ),
             'not_found' => __( 'No shows found' ),
             'not_found_in_trash' => __( 'No shows found in Trash' ),
             'parent' => __( 'Parent Show' ),
                ),
 
             'public' => true,
             'show_ui' => true,
             'publicly_queryable' => true,
             'exclude_from_search' => false,
             'menu_position' => 10,
             'menu_icon' => get_stylesheet_directory_uri() . '/img/nrt-shows.png',
             'hierarchical' => true,
             'query_var' => true,
             'rewrite' => array( 'slug' => 'shows', 'with_front' => false ),
             'taxonomies' => array( 'post_tag', 'category'),
             'can_export' => true,
             'supports' => array(
             'post-thumbnails',
             'excerpts',
             'comments',
             'revisions',
             'title',
             'editor',
             'page-attributes',
             'custom-fields')
             )
             );
}

To add custom post types to the Menus options on the Menus page accessible from the Dashboard (choose Appearance→Menus), click the Screen Options tab at the top right of that page.

You see a check box next to Post Types that you can select to enable your custom post types in the menus you create. (The Post Types appear in the Screen Options only if you have custom post types enabled in your theme.)

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
5 Developers of Premium WordPress Themes
The Settings Pages for 3 Popular WordPress Plugins
How to Add WordPress Widgets to Sidebars or Footers
How to Change the Name of a WordPress Category
The Layout and Structure of the WordPress Twenty Twelve Theme
Advertisement

Inside Dummies.com