How to add a custom post type to Thesis Theme

How to add a custom post type to Thesis Theme

Custom post types are nothing new to WordPress, they’ve been around since WordPress 3.0. The latest versions of Thesis 2.x makes it even easier to add and use them on your site.

This tutorial requires both changes to your Custom.php file and the creation of a new template in your skin editor. This tutorial is a simple follow along, just change the “Thesis New” custom type name for your own.

1) Begin with adding the code to add the custom post type

We’re going to begin with adding the code required to add the custom post type to your WordPress backend.

There are WordPress plugins, such as ‘Custom Post Type UI’ that you can use to create your custom post type; but we are going to do this ourselves as the code to add is straightforward. This also means that there isn’t yet another plugin you need to maintain in your install.

The following code snippet needs to be added to your custom.php file. If you need a guide on how to edit your custom.php file, check out my thesis tips tutorial here.

/* Custom Post */
function Thesis_News_custom_init() {
      $labels = array(
          'name' => 'Thesis News',
          'singular_name' => 'Thesis News',
          'add_new' => 'Add New Thesis News',
          'add_new_item' => 'Add New Thesis News',
          'edit_item' => 'Edit Thesis News',
          'new_item' => 'New Thesis News',
          'all_items' => 'All Thesis News',
          'view_item' => 'View Thesis News',
          'search_items' => 'Search Thesis News',
          'not_found' =>  'No Thesis News found',
          'not_found_in_trash' => 'No Thesis News found in Trash', 
          'parent_item_colon' => '',
          'menu_name' => 'Thesis News',
          );

      $args = array(
          'labels' => $labels,
          'exclude_from_search' => false,
          'public' => true,
          'publicly_queryable' => true,
          'show_ui' => true, 
          'show_in_menu' => true, 
          'query_var' => true,
          'rewrite' => array( 'slug' => 'Thesis News' ),
          'capability_type' => 'post',
          'has_archive' => false, 
          'hierarchical' => false,
          'taxonomies' => array('category'),
          'menu_position' => null,
          'supports' => array( 'title', 'author', 'thumbnail', 'excerpt', 'editor' )
          ); 

        register_post_type( 'Thesis News', $args );
    }
    add_action( 'init', 'Thesis_News_custom_init', 0);

You need to copy and paste the code. Change the ‘Thesis News’ custom post type name to your own, then save and upload as per the tutorial post.

Once added, you will see the new Custom Post Type in your WordPress backend.

Custom post type added to WordPress

Custom post type added to WordPress

2) Create your skin custom template

Now that you have the custom post type available, you can start to add new posts. However, these will not be shown on the site until you create the page for viewing them.

To do this, first, you will need to create a custom template to be used by this page. Start by going to the menu option ‘Thesis -> Skin Editor’.

Once there, you will need to create a custom template. You do this by first, clicking on the yellow coloured button, when entering the page this should have Home on it.

Create your custom template

Create your custom template

Then from the drop-down, click the ‘ADD NEW’ blue button, type in your template name and it will create the blank template for you to start designing.

3) Design your template

This is where the magic happens, so to speak. You need to design your template; I would recommend you take a look at your Home template and design it as close to that as possible.

You can see my design in the below image.

New custom template

New custom template

The important thing here is as follows:

In your WP Loop, make sure you use the Query Box and not Post Box. You will likely find in your Home or other templates, they use the Post Box, however, only the Query Box will allow you to choose your custom post type (at least at present).

Once you have your template setup, go to the Query Box and click the gear icon

Query Box Gear Icon

Query Box Gear Icon

This opens up the configuration for the box.

Once done, complete this part task by clicking the green Save Template button in the top right.

4) Create your new page

The final thing required is to create a page which will use this template and display your custom posts.

Start by going to the Pages -> Add New menu item to create a new page.

Name it whatever you want it to be. Then, on the right-hand side look for the Page Template section (in Classing Response Skin its called ‘Classic Response Skin Custom Template’.

When located, click the drop-down menu and choose your new custom template.

Choose template for page

Choose template for page

Save your page and you’re ready to go. Simply add this page to your menu and anyone visiting can go and check out your custom post types.

About the author: I’m a Software Engineer by trade and for a while I have been spending my time creating Websites and Blogs with Wordpress. I recently started to use the Thesis Framework and found only a few tutorials and help. So, I started this site to document what I learn and to share with others. I’m also available to help on a one to one basis for those that would like to work with me.

{ ( 0 comments… add one ) }

Leave a Comment