Tags

posttype

add this code in function.php or create a file in theme inc folder posttypes.php

and add this line in function.php file
require get_template_directory() . ‘/inc/posttypes.php’;

add_action('init', 'posttype_register');
 
function posttype_register() {
 
	$labels = array(
		'name' => 'Post Name',
		'singular_name' => 'Post Singular Name',
		'add_new' => 'Add New',
		'add_new_item' => 'Add New Item',
		'edit_item' => 'Edit Item',
		'new_item' => 'New Item',
		'view_item' => 'View Item',
		'search_items' => 'Search',
		'not_found' => 'Nothing found',
		'not_found_in_trash' => 'Nothing found in Trash',
		'parent_item_colon' => '',
		'menu_name' => 'Post Menu Name'
	);
 
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'query_var' => true,
		'menu_icon' => get_stylesheet_directory_uri() . '/images/icon.png',
		'rewrite' => true,
		'capability_type' => 'post',
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array('title','thumbnail')
	  ); 
 
	register_post_type( 'posttypename' , $args );
}

 

Call Custom Post Type Posts

<?php $type = 'posttypename'; $args=array( 'post_type' => $type,
	'post_status' => 'publish',
	'posts_per_page' => 10,
	'caller_get_posts'=> 1);
	
	$my_query = null;
	$my_query = new WP_Query($args);
	
	while ($my_query->have_posts()) : $my_query->the_post(); ?>

<h2><?php the_title(); ?></h2>


<div><?php the_content(); ?></div>


<div><?php the_post_thumbnail('full'); ?></div>


	<?php endwhile; wp_reset_query(); ?>

Advertisements