Blog Post Icon
Blog
01/15/2015

Creating custom post types and pulling them into a custom page template in WordPress

Hello!

Occasionally in WordPress it is necessary to push, what is primarily a blogging content management system, to its limits in order to create a dynamic website.

The reason why it may be necessary to create a custom wordpress post type is in just that scenario where you need to create custom and dynamic types of content that go beyond what a wordpress blog “post” by default will allow you to modify.

For example you may want to create a car website that lists all sorts of different cars and has a multiple car listing page and single car listing pages. Each car could have many fields like color, make, model, year, engine, features and so on. Doing this in a wordpress blog post just wouldn’t work because out of the box you only have fields like post title, categories, tags and post content.

While it is possible to simply paste all the data in a table in the WYSIWYG editor, wouldn’t it be nice to have the “color” and “model” fields of that car as separately defined fields? The advantage with that is that you can then “pull” those individual fields and create a really dynamic and amazing page template that arranges all these fields in different ways.

Create a custom post type with a plugin

There are many free and commercial wordpress plugins that accommodate ways to create a custom post types, one of which that is worth noting is the Types plugin. This plugin allows you to circumvent the (minor) php development that would be necessary to manually create your custom post type. You still will need to develop the custom page template that “pulls” this data, but at least the first part of the problem can be done by a web interface instead.

The documentation for this plugin includes an informative how-to video that demonstrates how to create the custom post type, fields and everything in between.

Edit your functions.php to create a custom post type

This method is obviously a little bit more advanced. To anyone who is comfortable with PHP and is familiar with WordPress, this should be quite easy. Basically this method is what the aforementioned plugin is doing through the web interface. An advantage of doing things this way is that you have more options for customizations and perhaps for connecting two different custom post types together such as making fields related or connected.

add_action( 'init', 'custom_post_type' );
function custom_post_type() {
register_post_type( 'the_car',
array(
'labels' => array(
'name' => __( 'Cars' ),
'singular_name' => __( 'Car' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'cars'),
)
);
}

What were doing in the above code snippet is essentially hooking into the init function and adding a new function that creates this new custom post type called “Cars”. The rest of the definitions like “slug” are pretty straightforward.

The next thing we want to do is add custom fields so that when you are adding or editing the custom post types you can add those “year” , “model” and whatever custom fields you feel is necessary :

add_action("admin_init", "admin_init");
 
function admin_init(){
  add_meta_box("car-year_meta", "Car Year", "car_year", "cars", "side", "low");
}

function car_year(){
  global $post;
  $custom = get_post_custom($post->;ID);
  $the_car_year = $custom["car_year"][0];
  ?>
  
  ;
  

That’s it! If this is something you can get comfortable with then you are really opening up the possibilities with WordPress because you can customize the way it handles and displays content to whatever you want, with whatever design considerations that you want as well.

At Shift8, we cater to all sorts of businesses in and around Toronto from small, medium, large and enterprise projects. We are comfortable adapting to your existing processes and try our best to compliment communication and collaboration to the point where every step of the way is as efficient as possible.

Our projects are typically broken into 5 or 6 key “milestones” which focus heavily on the design collaboration in the early stages. We mock-up any interactive or unique page within your new website so that you get a clear picture of exactly how your design vision will be translated into a functional website.

Using tools like Basecamp and Redpen, we try to make the process simple yet fun and effective. We will revise your vision as many times as necessary until you are 100% happy, before moving to the functional, content integration and development phases of the project.

For the projects that are more development heavy, we make sure a considerable amount of effort is spent in the preliminary stages of project planning. We strongly believe that full transparency with a project development plan ensures that expectations are met on both sides between us and the client. We want to ensure that the project is broken into intelligent phases with accurate budgetary and timeline breakdowns.

Approved design mock-ups get translated into a browse-ready project site where we revise again and again until you are satisfied. Client satisfaction is our lifeblood and main motivation. We aren’t happy until you are.

Need Web Design?

Fill out the form to get a free consultation.

shift8 web toronto – 416-479-0685
203A-116 geary ave. toronto, on M6H 4H1, Canada
© 2023. All Rights Reserved by Star Dot Hosting Inc.

contact us
phone: 416-479-0685
toll free: 1-866-932-9083 (press 1)
email: sales@shift8web.com

Shift8 Logo