Custom post type

Paste in functions.php (Register)

<?php
add_action( ‘init’, ‘codex_book_init’ );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {
$labels = array(
‘name’               => _x( ‘Books’, ‘post type general name’, ‘your-plugin-textdomain’ ),
‘singular_name’      => _x( ‘Book’, ‘post type singular name’, ‘your-plugin-textdomain’ ),
‘menu_name’          => _x( ‘Books’, ‘admin menu’, ‘your-plugin-textdomain’ ),
‘name_admin_bar’     => _x( ‘Book’, ‘add new on admin bar’, ‘your-plugin-textdomain’ ),
‘add_new’            => _x( ‘Add New’, ‘book’, ‘your-plugin-textdomain’ ),
‘add_new_item’       => __( ‘Add New Book’, ‘your-plugin-textdomain’ ),
‘new_item’           => __( ‘New Book’, ‘your-plugin-textdomain’ ),
‘edit_item’          => __( ‘Edit Book’, ‘your-plugin-textdomain’ ),
‘view_item’          => __( ‘View Book’, ‘your-plugin-textdomain’ ),
‘all_items’          => __( ‘All Books’, ‘your-plugin-textdomain’ ),
‘search_items’       => __( ‘Search Books’, ‘your-plugin-textdomain’ ),
‘parent_item_colon’  => __( ‘Parent Books:’, ‘your-plugin-textdomain’ ),
‘not_found’          => __( ‘No books found.’, ‘your-plugin-textdomain’ ),
‘not_found_in_trash’ => __( ‘No books found in Trash.’, ‘your-plugin-textdomain’ )
);

$args = array(
‘labels’             => $labels,
‘public’             => true,
‘publicly_queryable’ => true,
‘show_ui’            => true,
‘show_in_menu’       => true,
‘query_var’          => true,
‘rewrite’            => array( ‘slug’ => ‘book’ ),
‘capability_type’    => ‘post’,
‘has_archive’        => true,
‘hierarchical’       => false,
‘menu_position’      => null,
‘supports’           => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘comments’ )
);

register_post_type( ‘book’, $args );
}
?>

Display where you want

<?php
//WordPress loop for custom post type
$my_query = new WP_Query(‘post_type=book&posts_per_page=-1’);
while ($my_query->have_posts()) : $my_query->the_post();
the_title();
the_content();
the_post_thumbnail();
endwhile;  wp_reset_query();
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: