Support » Themes and Templates » custom loop question

  • wplearner


    Hey so I’m trying to learn the basics of custom loops, so I set up a single.php template in a childtheme of the sandbox theme, and I put the following code in it:

    [please follow the forum guidelines for posting and marking code]

    <?php get_header() ?>

    <div id=”container”>
    <div id=”content”>
    $myPosts = new WP_Query();
    while($myPosts->have_posts()) : $myPosts->the_post();
    ?><?php the_content();?>
    <?php endwhile; ?>
    <?php comments_template() ?>

    </div><!– #content –>
    </div><!– #container –>

    <?php get_sidebar() ?>
    <?php get_footer() ?>

    But whenever I run this on a single post I get an error saying:

    Parse error: syntax error, unexpected ‘=’ in /home/a9394669/public_html/wp-content/themes/mytheme/single.php on line 7

    Which doesn’t make any sense to me, because that’s part of the parameter. Can someone tell me what I’m doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer


    Why would you query single.php like this? It’s normal for single.php to just show one post.
    You used the wrong quotes in $myPosts->query(’posts_per_page=1’);
    change it to this: $myPosts->query('posts_per_page=1');



    hey thanks much Keesie, had no idea there are different types of single quotes. But how did you get the non slanted ones? also I’m really just trying to experiment with different parameters though I take your point.



    hmm, maybe it’s because I was editing it from within the host server and it’s doing some weird formating.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom loop question’ is closed to new replies.