• 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)
  • Try adding some content to one of your published Pages.

    Thread Starter alemao85

    (@alemao85)

    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?

    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?

    Thread Starter alemao85

    (@alemao85)

    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?

    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

    (@alemao85)

    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 🙂

    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

    (@alemao85)

    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.

    Where’s The Loop?

    Thread Starter alemao85

    (@alemao85)

    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.

    You need to look at creating a static front page. Your selected main posts page will then use index.php – which still needs a Loop.

    Thread Starter alemao85

    (@alemao85)

    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.

    Your page.php template file also needs a Loop.

    Thread Starter alemao85

    (@alemao85)

    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.