Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I display the loop inside a static page? Like the loop when I use the search (which in this theme it's actually working) or on index.php

An example for what I'm saying can be seen here: http://www.gaganews.com.br/noticias/ I want a page like this, showing all my posts with pagination, since my home page is kinda like the homepage here: http://www.gaganews.com.br/

I tried creating a template page, this way:

<?php

 /*
Template Name: Noticias
*/

get_header(); ?>

<div id="loop"><?php if ( have_posts() ) : ?>
        <?php
            get_template_part( 'loop', 'index' );
        ?>  
<?php endif; ?>
</div>
<div id="sidebar_single"><?php get_sidebar(); ?></div>
<?php get_footer(); ?>

I'm almost 100% sure that it's not the right way, but that's what I tried - like it was a "classic" index.php.

Then I created a blank page with this template, but with it instead of showing the latest posts on the page, it ONLY shows the PAGE TITLE itself: "News, posted on 1 de abril de 2013 by admin | Leave a comment | Edit" etc, but with all the CSS configuration from the loop (which means it's actually calling it, right?).

What could I do to achieve what I'm looking for?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You could use query_posts() to set up a new loop in your page. Assuming that the posts you want are in the category 'Noticias', with a slug of 'noticias':

query_posts( 'category=noticias' );
if( have_posts() ) {
    get_template_part( 'loop', 'index' );
}
wp_reset_query(); // probably not necessary, if you don't have a pre-existing Loop
share|improve this answer
    
That worked, thank you! I just needed to add an extra parameter (codex.wordpress.org/…) because I wanted pagination and it wasn't working properly (without it, on other pages it would keep displaying the same posts). But that's it. –  Otavio Vidal Apr 2 '13 at 16:30

You can simply use an iframe to wrap your query and place the iframe on any html or php page without having to touch your current page code.... See detail explanation on this link: http://allnigeriansinspain.com/blog/show-wordpress-post-on-static-html-page/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.