Forums

While Loop Limit Post Issue (6 posts)

  1. KX254F
    Member
    Posted 1 year ago #

    I understand php enough to get my self into trouble. Right now I'm in trouble. I want to pull 3 posts from a category by using a while loop. Right now it doesn't limit it to 3. What am I doing wrong?

    Here's the code.

    <?php query_posts('cat=4'); ?>
    <?php if (have_posts()) : $count = 0; ?>
    <?php while (have_posts()) : the_post(); $count <= 2; $count++; ?>

    <h4>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></h4>
    <p class="post-details"><?php _e('Posted on',woothemes); ?> <?php the_time('d. M, Y'); ?> | " rel="bookmark" title="Read More">Read More
    <hr />

    <?php endwhile; ?>
    <?php endif; ?>

  2. KX254F
    Member
    Posted 1 year ago #

    Part of it was missing. Nothing crucial but wanted to re-post.

    <?php query_posts('cat=4'); ?>
    <?php if (have_posts()) : $count = 0; ?>
    <?php while (have_posts()) : the_post(); $count <= 2; $count++; ?>

    <h4>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></h4>
    <p class="post-details"><?php _e('Posted on',woothemes); ?> <?php the_time('d. M, Y'); ?> | " rel="bookmark" title="Read More">Read More
    <hr />

    <?php endwhile; ?>
    <?php endif; ?>

  3. KX254F
    Member
    Posted 1 year ago #

    Never mind. it's just making links when I post because of the href's

  4. KX254F
    Member
    Posted 1 year ago #

    Anyone?

  5. KX254F
    Member
    Posted 1 year ago #

    I solved it. If anyone finds this down the road. This is what I did.

    Added this to the query: &posts_per_page=3

    So now it looks like this:

    <?php query_posts('cat=4&posts_per_page=3'); ?>
    <?php if (have_posts()) : $count = 0; ?>
    <?php while (have_posts()) : the_post(); $count <= 2; $count++; ?>

  6. mrkeroppi
    Member
    Posted 1 year ago #

    Seeing as this thread was so lonely, thought I would just say thanks KX254F.

Topic Closed

This topic has been closed to new replies.

About this Topic