Title: Loop in page template
Last modified: August 20, 2016

---

# Loop in page template

 *  [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/)
 * Hello,
    I have created my own WP theme.
 * Now I added a loop to see posts to the index.php and it works. But I dont want
   to have the blog on all pages so I created a page template (just copied the index.
   php and added the page template stuff at the top) and added the same loop there.
   Then created a new page and aplied the page template. But the blog content does
   not appear?
 * Why? Can’t I use the loop in page templates?
 * Thanks a lot!

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386498)
 * Try adding some content to one of your published Pages.
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386504)
 * The content appears, but nothing from the blog.
 * Let me ask differente…maybe I am on a wrong way here.
 * So what I have:
 * A index.php (and header.php and so on) and some CSS.
    Now there is no Loop in
   this index.php.
 * I want to have several pages on my blog and they will use all the °default” page
   template (index.php).
 * Now in one of those pages I want to show the last 10 posts for example. Thats
   why my idea was to copy the index.php rename it, add the loop and use it as page
   template for the page here I want the blog.
 * Is that the right way?
    I was playing arround and added a last-post widget. There
   the title of the posts appear and when I click on one it opens the blog-post 
   in my index.php template. So maybe to have a page with a loop I dont need a seperate
   template?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386506)
 * > they will use all the °default” page template (index.php).
 * The default template for Pages is actually page.php. Until you have more experience
   in creating themes, I would not advise you to try and create a single template
   file theme. Have you reviewed [Theme Development](http://codex.wordpress.org/Theme_Development)?
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386523)
 * Hello,
    I will stay with a single template theme. So I just copied to content
   from index.php to page.php and added the template stuff to the top of the page.
   php.
 * But now I still dont want to show the Loop on all pages that I create. Only on
   one that I call Blog.
 * Is that possible?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386526)
 * > added the template stuff to the top of the page.php.
 * What template stuff?
 * > Is that possible?
 * I don’t think you understand how theme templates work. Have you reviewed the 
   page at the link I posted above yet?
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386544)
 * Hello,
    yes i read it. Thanks!
 * I understand that WP looks first for a specific page template if it is set for
   a page.
    Then it uses page.php, and if there is no page.php it uses index.php.
   Thats why my index.php and page.php is the same. Since I have a page.php I assume
   that index.php wont be used so I talk about page.php now.
 * My page.php contains a header, a footer and a sidebar. But the main part is empty.
   Now I can create a new page and write some text and ans when I preview the page
   I see the page.php template with the text I wrote in the main part. So far so
   good. I can add several pages now (about, products, …) and so on.
 * Now I want to have one page where it shows the blog content. And that’s the problem
   that I am trying to solve here 🙂
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386546)
 * > My page.php contains a header, a footer and a sidebar.
 * to avoiud problems down the line, you would be better off taking these common
   areas out of the page.php and index.php template files and creating header.php,
   sidebar.php and footer.php files. These can be called in index.php and page.php
   using get_header(), get_sidebar() and get_footer() respectively.
 * > And that’s the problem that I am trying to solve here
 * That will be your theme’s index.php template file. What code are you using in
   this template once you have implemented the separate header, sidebar and footer
   files?
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386550)
 * Sorry, I wasn’t clear. I meant that I include header, footer and sitebar in the
   index.php
 *     ```
       <?php get_header(); ?>
       <div class="left-content">
   
       	Content
   
       </div><!-- Close left-content -->
       <div class="right-content">
       	<?php /* Widgetized sidebar */
       	    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Barra Lateral') ) : ?>
       	<?php endif; ?>
       </div><!-- Close right-content -->
       <div class="clear"></div><!-- Close clear -->
       <?php get_footer(); ?>
       ```
   
 * That’s how it looks. The page.php looks exactly the same.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386554)
 * Where’s [The Loop](http://codex.wordpress.org/The_Loop)?
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386564)
 * Sorry, I am a little confused.
 * Let’s say I have a domain: domain.com
 * And I have pages:
 * domain.com/about
    domain.com/services
 * Now if I go to domain.com it will load the index.php. I don’t know yet how to
   change the content of that page because it’s not really a page listed under “
   Pages”. Of course I can add content (and also the loop) to the index.php, but
   I dont want it on the startpage.
 * Now if I go to domain.com/about or domain.com/services it will load the page.
   php with the content that I have created under “Pages”
 * I want to have domain.com/blog where it shows The Loop.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386567)
 * You need to look at [creating a static front page](http://codex.wordpress.org/Creating_a_Static_Front_Page).
   Your selected main posts page will then use index.php – which still needs a Loop.
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386579)
 * Great, this link is what I needed 🙂 Thanks!
 * Now it works.
 * Only one problem: No it shows the blog under /blog
 * Additionally I created a home and a about page and wrote some text. But the text
   does not appear anymore.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386739)
 * Your page.php template file also needs a Loop.
 *  Thread Starter [alemao85](https://wordpress.org/support/users/alemao85/)
 * (@alemao85)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386741)
 * That worked! Thanks a lot!!

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

The topic ‘Loop in page template’ is closed to new replies.

 * 14 replies
 * 2 participants
 * Last reply from: [alemao85](https://wordpress.org/support/users/alemao85/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/loop-in-page-template-1/#post-3386741)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
