How to add Custom Post Types

You can add a custom Post type to your WordPress theme by including the following in your theme’s functions file. Just change the names to match what you need.

add_action('init', 'js_custom_init');
function js_custom_init() 
{
  $labels = array(
	'name' => _x('Banner', 'post type general name'),
    'singular_name' => _x('Banner', 'post type singular name'),
    'add_new' => _x('Add New', 'banner'),
    'add_new_item' => __('Add New Banner'),
    'edit_item' => __('Edit Banner'),
    'new_item' => __('New Banner'),
    'view_item' => __('View Banner'),
    'search_items' => __('Search Banner'),
    'not_found' =>  __('No slides found'),
    'not_found_in_trash' => __('No slides found in Trash'), 
    'parent_item_colon' => '',
    'menu_name' => 'Banner'
  );
  $args = array(
	'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => false, 
    'hierarchical' => false,
    'menu_position' => 20,
    'supports' => array('title','editor','custom-fields','thumbnail')
  ); 
  register_post_type('banner',$args);  
}

Once you’ve included the function, you can call it in your theme by adding a custom post type query.

 'episode', 'posts_per_page' => 1 );
	$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();?>

All of your amazing stuff...

Leave a Reply

Your email address will not be published. Required fields are marked *

30 − 21 =