JiveDig
6/3/2013 - 7:00 PM

Register videos custom post type

Register videos custom post type

// Register 'videos' Post Type
if ( ! function_exists('jivedig_videos_post_type') ) {
function jivedig_videos_post_type() {
	$labels = array(
		'name'                => _x( 'Videos', 'themename' ),
		'singular_name'       => _x( 'Video', 'themename' ),
		'menu_name'           => __( 'Videos', 'themename' ),
		'parent_item_colon'   => __( 'Parent Video:', 'themename' ),
		'all_items'           => __( 'All Videos', 'themename' ),
		'view_item'           => __( 'View Video', 'themename' ),
		'add_new_item'        => __( 'Add New Video', 'themename' ),
		'add_new'             => __( 'New Video', 'themename' ),
		'edit_item'           => __( 'Edit Video', 'themename' ),
		'update_item'         => __( 'Update Video', 'themename' ),
		'search_items'        => __( 'Search Videos', 'themename' ),
		'not_found'           => __( 'No Videos found', 'themename' ),
		'not_found_in_trash'  => __( 'No Videos found in Trash', 'themename' ),
	);
 
	$rewrite = array(
		'slug'                => 'videos',
		'with_front'          => true,
		'pages'               => true,
		'feeds'               => true,
	);
 
	$args = array(
		'label'               => __( 'videos', 'themename' ),
		'description'         => __( 'Videos section of website', 'themename' ),
		'labels'              => $labels,
		'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'comments' ),
/* 		'taxonomies'          => array( 'category', 'post_tag' ), */
		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'show_in_nav_menus'   => true,
		'show_in_admin_bar'   => true,
		'menu_position'       => 5,
/* 		'menu_icon'           => '', */
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		'query_var'           => 'videos',
		'rewrite'             => $rewrite,
		'capability_type'     => 'page',
	);
	
	register_post_type( 'videos', $args );
}
// Hook into the 'init' action
add_action( 'init', 'jivedig_videos_post_type', 0 );
}
 
/** Change the number of video items to be displayed (props Bill Erickson) */
add_action( 'pre_get_posts', 'jivedig_video_archive_count' );
function jivedig_video_archive_count( $query ) {
	if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'videos' ) ) {
		$query->set( 'posts_per_page', '12' );
	}
}