Custom Post Type

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

2 thoughts on “Custom Post Type

  1. its for getting image size you can also choose different sizes

    the_post_thumbnail(); // without parameter -> ‘post-thumbnail’

    the_post_thumbnail( ‘thumbnail’ ); // Thumbnail (default 150px x 150px max)
    the_post_thumbnail( ‘medium’ ); // Medium resolution (default 300px x 300px max)
    the_post_thumbnail( ‘large’ ); // Large resolution (default 640px x 640px max)
    the_post_thumbnail( ‘full’ ); // Full resolution (original size uploaded)

    the_post_thumbnail( array(100, 100) ); // Other resolutions

    Like

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s