Title: Custom Posts Page Template
Last modified: August 20, 2016

---

# Custom Posts Page Template

 *  [ealatrebi](https://wordpress.org/support/users/ealatrebi/)
 * (@ealatrebi)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/custom-posts-page-template/)
 * I am trying to display posts using a custom page tempalte. I set up my blogs 
   page through Settings/Reading and defining the page there, and then defining 
   the template in that page. The code in the template page is:
 *     ```
       <?php
       /*
       Template Name: Blog page
       */
   
       while(have_posts()) { // original main loop - page content
         the_post();
         the_title(); // title of the page
         the_content(); // content of the page
         // etc...
       }
   
       // now we display list of our custom-post-type posts
   
       // first obtain pagination parametres
       $paged = 1;
       if(get_query_var('paged')) {
         $paged = get_query_var('paged');
       } elseif(get_query_var('page')) {
         $paged = get_query_var('page');
       }
   
       // query posts and replace the main query (page) with this one (so the pagination works)
       query_posts(array('post_type' => 'my_post_type', 'post_status' => 'publish', 'paged' => $paged))
   
       // pagination
       next_posts_link();
       previous_posts_link();
   
       // loop
       while(have_posts()) {
         the_post();
         the_title(); // your custom-post-type post's title
         the_content(); // // your custom-post-type post's content
       }
   
       wp_reset_query() // sets the main query (global $wp_query) to the original page query (it obtains it from global $wp_the_query variable) and resets the post data
   
       // So, now we can display the page-related content again (if we wish so)
       while(have_posts()) { // original main loop - page content
         the_post();
         the_title(); // title of the page
         the_content(); // content of the page
         // etc...
       }
   
       ?>
   
       <?php get_header(); ?>
       	<div id="container" class="clrfix">
       		<div class="contents">
       			<?php if ( have_posts() ): while ( have_posts() ): the_post(); ?>
   
       				<p>Date: <?php echo date("l, F d, Y"); ?> | <?php comments_number(); ?></p>
   
       				<?php the_content(); ?> 
   
       				<h4>This is post #<?php the_ID(); ?> | Author: <?php the_author(); ?></h4>
       				<p>Filed under: <?php the_category(','); ?> | <?php edit_post_link(); ?></p>
   
       			<?php endwhile; ?>
   
       			<p><?php previous_post_link(); ?> | <?php next_post_link(); ?></p>
   
       		<?php else : ?>
   
       			<p>Sorry, no posts matched your criteria.</p>
   
       		<?php endif; ?>
       		</div>
       		<div class="sidebar">
       			<?php get_sidebar(); ?>
       		</div>
       	</div>
   
       <?php get_footer(); ?>
       ```
   
 * It is not working and displaying the regular index.php format. What am I doing
   wrong?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Christine Rondeau](https://wordpress.org/support/users/crondeau/)
 * (@crondeau)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/custom-posts-page-template/#post-3258226)
 * I don’t understand why you would want to do this? If you’ve set your settings
   > reading to a static page and then a page for your posts, then your page.php
   will be used for your homepage and the index.php used for your blog.
 * If you want to make the index.php look different, just copy the code you’ve inserted
   in your custom template in your index.php.
 *  Thread Starter [ealatrebi](https://wordpress.org/support/users/ealatrebi/)
 * (@ealatrebi)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/custom-posts-page-template/#post-3258228)
 * Excellent, thank you! I didn’t realize the hierarchy of things, I didn’t have
   a page.php file to begin with, renamed/saved index.php to that and applied the
   custom posts page to index.php, works fine now. Thanks again 🙂
 *  [Christine Rondeau](https://wordpress.org/support/users/crondeau/)
 * (@crondeau)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/custom-posts-page-template/#post-3258231)
 * I like to use front-page.php for my home page. If I’m making a unique looking
   homepage, I find that this template works really well for static content and 
   then I use the index.php for the blog.
 * But if what you have works, then great. Glad I could help.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Posts Page Template’ is closed to new replies.

## Tags

 * [custom pages](https://wordpress.org/support/topic-tag/custom-pages/)
 * [custom posts](https://wordpress.org/support/topic-tag/custom-posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Christine Rondeau](https://wordpress.org/support/users/crondeau/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/custom-posts-page-template/#post-3258231)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
