Query WordPress Post:
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
Query WordPress Post from Specific category(sports):
<?php query_posts('post_type=post&category_name=sports&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
Query WordPress Post from Specific category(sports):
<?php query_posts('post_type=post&category_name=sports&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
Example
<?php
/*
Template Name: Category Template
*/
get_header(); ?>
<div class="maincontent">
<div class="widthtemp">
<div class="column_one ">
<h2>Posts From Sports Category</h2>
<?php query_posts('post_type=post&category_name=Sports&post_status=publish&posts_per_page=2&paged='. get_query_var('paged'));
?>
<?php get_template_part('post-loop'); ?>
</div>
<div class="column_two ">
<h2>Posts From Others Category</h2>
<?php query_posts('post_type=post&category_name=Others&post_status=publish&posts_per_page=2&paged='. get_query_var('paged')); ?>
<?php get_template_part('post-loop'); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
/*
Template Name: Category Template
*/
get_header(); ?>
<div class="maincontent">
<div class="widthtemp">
<div class="column_one ">
<h2>Posts From Sports Category</h2>
<?php query_posts('post_type=post&category_name=Sports&post_status=publish&posts_per_page=2&paged='. get_query_var('paged'));
?>
<?php get_template_part('post-loop'); ?>
</div>
<div class="column_two ">
<h2>Posts From Others Category</h2>
<?php query_posts('post_type=post&category_name=Others&post_status=publish&posts_per_page=2&paged='. get_query_var('paged')); ?>
<?php get_template_part('post-loop'); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
Register Custom Post
functions.php:
function create_post_type() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'Testimonial' ),
'singular_name' => __( 'Testimonial' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Testimonial' ),
'edit_item' => __( 'Edit Testimonial' ),
'new_item' => __( 'New Testimonial' ),
'view_item' => __( 'View Testimonial' ),
'not_found' => __( 'Sorry, we couldn't find the Testimonial you are looking for.' )
),
'public' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'testimonial' ),
'supports' => array( 'title', 'editor', 'custom-fields' )
)
);
}
add_action( 'init', 'create_post_type' );
Note: One can add many field:
'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' )
Query Post in Custom Page Template:
<?php query_posts('post_type=testimonial&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
function create_post_type() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'Testimonial' ),
'singular_name' => __( 'Testimonial' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Testimonial' ),
'edit_item' => __( 'Edit Testimonial' ),
'new_item' => __( 'New Testimonial' ),
'view_item' => __( 'View Testimonial' ),
'not_found' => __( 'Sorry, we couldn't find the Testimonial you are looking for.' )
),
'public' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'testimonial' ),
'supports' => array( 'title', 'editor', 'custom-fields' )
)
);
}
add_action( 'init', 'create_post_type' );
Note: One can add many field:
'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' )
Query Post in Custom Page Template:
<?php query_posts('post_type=testimonial&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
Example
<?php
/*
Template Name:Testimonial
*/
get_header(); ?>
<div class="breadcrumbs">
<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>
</div>
<div class="maincontent">
<?php get_sidebar();?>
<div class="content ">
<?php query_posts('post_type=testimonial&post_status=publish&posts_per_page=10&paged='. get_query_var('paged'));
?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h2 id="testimonil_title">Testimonial</h2>
<div class="single_testimonial fix">
<div class="client_comments">
<?php the_content();?>
</div>
<div class="client_name">
<?php the_title();?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
/*
Template Name:Testimonial
*/
get_header(); ?>
<div class="breadcrumbs">
<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>
</div>
<div class="maincontent">
<?php get_sidebar();?>
<div class="content ">
<?php query_posts('post_type=testimonial&post_status=publish&posts_per_page=10&paged='. get_query_var('paged'));
?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h2 id="testimonil_title">Testimonial</h2>
<div class="single_testimonial fix">
<div class="client_comments">
<?php the_content();?>
</div>
<div class="client_name">
<?php the_title();?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
Note
One can query to show one post in homepage( creating a testimonial option) and give link to the custom template page to show more.
<div class="content ">
<php
query_posts('post_type=testimonial&post_status=publish&posts_per_page=1&paged='. get_query_var('paged'));
?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h2 id="testimonil_title">Testimonial</h2>
<div class="single_testimonial fix">
<div class="client_comments">
<?php the_content();?>
</div>
<div class="client_name">
<?php the_title();?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<php
query_posts('post_type=testimonial&post_status=publish&posts_per_page=1&paged='. get_query_var('paged'));
?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h2 id="testimonil_title">Testimonial</h2>
<div class="single_testimonial fix">
<div class="client_comments">
<?php the_content();?>
</div>
<div class="client_name">
<?php the_title();?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>