I know this is a really newbie question, but I can’t seem to get the loop to pull from the posts. all it is doing is pulling from the page itself.

I made a template and added the loop to it.

<?php
if( have_posts() ) {
  while( have_posts() ) {
    the_post();
    ?>
    <h2><?php the_title(); ?></h2>
    <?php
  }
}
?>

edit: here is all the code: http://pastebin.com/k2rDu53b

1
1

Because you’re on a page, that’s only going to display the query for that page. As such, you’d have to create a new query to bring in the posts you want. Replace your loop with this:

<?php
    $args = array(
        'post_type' => 'post'
    );

    $post_query = new WP_Query($args);

    if($post_query->have_posts() ) {
        while($post_query->have_posts() ) {
            $post_query->the_post();
            ?>
            <h2><?php the_title(); ?></h2>
            <?php
            }
        }
?>

Here some more information on the query: http://codex.wordpress.org/Class_Reference/WP_Query

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *