In WordPress 3.0 there is a new feature custom post types,giving a ability to create blog type pages and present content same way as a blog page but will not have the posted by or the date on the page.

There two ways to have custom post types by installing a plugin and other way is as below by adding code in functions.php file and creating page template.

This tutorial will show how to create a custom post type that will have label in your admin panel same way you have pages and posts and the way to show on your theme as page with out using any plugin.

In this example we will create a custom post type called News and it can be called anything you want all you will need to do is change the names News and news to your own name in code.

The first step

Add this code in functions.php

// Creates News post type
register_post_type('news', array(
'label' => 'News',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'news'),
'query_var' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',)
));

Second step

Page template

In this step we will be creating a template for custom post type so open page.php in a editor like Notepad++ and make changes.

Top of page.php we change the code so we create a page template replace top to


/**
 * Template Name: News Page
 *
 * Selectable from a dropdown menu on the edit page screen.
 */
?>

P.S
News Page Change to your page template name.

before the header code.

Third Step

add

php query_posts( 'post_type=news'); ?> 

just after

<div id="content" role="main">

and the other change to be made is so that it only displays the excerpt and to view full page visitor can click Continue Reading link.
We change the_content to the_excerpt in

<?php the_content(); ?>

and save as any other name in this example I am saving as news-page.php and upload the file in your themes folder.

Once you have made changes you will see that you have new lable in admin and this example is News and now to display the page in your menu we create a blank page and you call it what ever you want I am calling it “In News” and in Page Attribute you will see a new template in drop down menu (in this example I called it News Page in the page code above) select the template and publish.

Click on News (the new label) and “add new” and add your content as if you are posting a article in blog and publish and now if you go and check the page you will have a new blog style page and when you add another content it fall above the previous one like a blog page.

Avatar of Govindji Patel

About

I am Author/Publisher WordPress Coach and Consultant who enjoys writing tutorials and helping wordpress users build better WordPress website/blog.

Related Posts

  • Thanks for this very clear tutorial, actually it’s quite impossible to find something like this.

  • Cristobal You are welcome glad to know that my article helped you.

  • In addition to this  Custom post add a level of flexibility to WordPress that makes this open-source Web development platform more useful on many levels.Nice post

blog comments powered by Disqus
Premium wordpress theme
Skype Status
Need Help with Wordpress Chat with me - Govindji Patel: My status is Online
» Get Skype, call free! If Offline please leave Message
Become A Fan
Free Report

WordPress Optimization Secrets

Get Your Blog To Rank Higher

Register and Download Free Report

Twenty Eleven Child Theme

Upgrade and get set of 35 videos on

how to create and customize child theme

Buy Me Coffee
Donation



Other Amount:



I appreciate a donation if you find my tutorials helpfull :



Your privacy will never be compromised or shared.
Congratulations

Thank you for Subscribing Please check your email for a confirmation email