Title: Create a Page Template
Last modified: August 31, 2016

---

# Create a Page Template

 *  Resolved [tgberk](https://wordpress.org/support/users/tgberk/)
 * (@tgberk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/)
 * Hello everyone,
 * First of all thank you for amazing support of this theme. I want to a create 
   custom page template which shows most viewed posts. So I’ve Wp-PostViews plugin,
   I asked for help at the plugin’s support page. They told me I need to create 
   page template and use the query_posts posts for it:
 * `<?php query_posts( array( 'meta_key' => 'views', 'orderby' => 'meta_value_num','
   order' => 'DESC' ) ); ?>`
 * Link to post from the plugin’s support: [https://wordpress.org/support/topic/create-a-most-popular-posts-page?replies=2](https://wordpress.org/support/topic/create-a-most-popular-posts-page?replies=2)
 * So I think I can create a page template with this code and default template of
   theme. I go to page template file (page.php). I see this:
 *     ```
       <?php get_header(); ?>
   
       <section class="content">
   
       	<?php get_template_part('inc/page-title'); ?>
   
       	<div class="pad group">
   
       		<?php while ( have_posts() ): the_post(); ?>
   
       			<article <?php post_class('group'); ?>>
   
       				<?php get_template_part('inc/page-image'); ?>
   
       				<div class="entry themeform">
       					<?php the_content(); ?>
       					<div class="clear"></div>
       				</div><!--/.entry-->
   
       			</article>
   
       			<?php if ( ot_get_option('page-comments') == 'on' ) { comments_template('/comments.php',true); } ?>
   
       		<?php endwhile; ?>
   
       	</div><!--/.pad-->
   
       </section><!--/.content-->
   
       <?php get_sidebar(); ?>
   
       <?php get_footer(); ?>
       ```
   
 * Where should I put the code I took from the plugin’s support? I couldn’t figure
   out this. I made most_viewed.php file and upload to human/page-templates.
 * I know my post is too long, sorry about this. Thanks in advance.

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

 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185578)
 * Hi tgberk. You should be able to modify the default post query without creating
   a new page template. You need to be using a child theme, which I assume you are
   since you also need to modify the theme files to add the code to display the 
   view count. In the child theme functions.php file try this:
 *     ```
       // sort posts on home page by number of views
       add_action('pre_get_posts','tgberk_modify_query');
       function tgberk_modify_query($query) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query-> set('meta_key', 'views');
               $query-> set('orderby', 'meta_value_num');
               $query-> set('order', 'DESC');
           }
       }
       ```
   
 * If you want to display all post lists (category, tag, etc.) this way then remove
   this part:
 *     ```
       $query->is_home() &&
       ```
   
 *  Thread Starter [tgberk](https://wordpress.org/support/users/tgberk/)
 * (@tgberk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185580)
 * I don’t want to show home page. I want to create a new page called “most viewed
   posts” and i want to show there. I think it is because i should create a new 
   page template, am I right?
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185590)
 * In that case you don’t need the above function. Try this:
 * 1. Copy archive.php (not page.php) to your child theme. Although the page.php
   code looks similar to a posts page, it will only retrieve the single page content.
   So you need to use a page that displays posts. Rather than create one from scratch,
   just use a theme file; then the layout will be the same as the rest of the theme.
 * 2. Rename the child theme archive.php to most-viewed-posts.php (or whatever you
   want to name it).
 * 3. Edit the file and add the page template header, new query arguments, new query,
   and reset the query afterwards. I coded up an example of what it might look like
   here: [http://pastebin.com/JsJ4myBM](http://pastebin.com/JsJ4myBM)
    You’re welcome
   to use that code if you’d like.
 * 4. Create a new page with a title of “Most Viewed Posts”; use the “Most Viewed
   Posts Page” template.
 * 5. Add the new page to your menu.
 * 6. Depending on which post layout you’re using you need to copy content.php or
   content-standard.php to your child theme and add the plugin code:
 *     ```
       <?php if(function_exists('the_views')) { the_views(); } ?>
       ```
   
 * 7. Add css to your child theme style.css file to position and style the view 
   count elements.
 * Let me know how that goes.
 *  Thread Starter [tgberk](https://wordpress.org/support/users/tgberk/)
 * (@tgberk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185592)
 * Thank you very very much, it worked perfectly. It is amazing, thank you for your
   effort. I have an another question can i change name of “tag” to “actors” and
   tag’s icon?
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185593)
 * You’re welcome; glad it worked. Your other question should be put in a new topic
   since it’s not really related to this one. If you don’t have any further questions
   about the template please mark this topic as Resolved. Thanks.
 *  Thread Starter [tgberk](https://wordpress.org/support/users/tgberk/)
 * (@tgberk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185597)
 * Thank you very much again, I am going to put a new topic for tag question.
 *  Thread Starter [tgberk](https://wordpress.org/support/users/tgberk/)
 * (@tgberk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185598)
 * Resolved.

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

The topic ‘Create a Page Template’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/hueman/3.7.27/screenshot.png)
 * Hueman
 * [Support Threads](https://wordpress.org/support/theme/hueman/)
 * [Active Topics](https://wordpress.org/support/theme/hueman/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/hueman/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/hueman/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [tgberk](https://wordpress.org/support/users/tgberk/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/create-a-page-template/#post-7185598)
 * Status: resolved