WordPress.org

Ready to get started?Download WordPress

Forums

custom loop question (4 posts)

  1. wplearner
    Member
    Posted 2 years ago #

    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">
    <?php
    $myPosts = new WP_Query();
    $myPosts->query(’posts_per_page=1’);
    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?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    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');

  3. wplearner
    Member
    Posted 2 years ago #

    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.

  4. wplearner
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic