WordPress.org

Ready to get started?Download WordPress

Forums

Strange problem (5 posts)

  1. blogger_a
    Member
    Posted 6 years ago #

    Hi.
    I am making a theme for my wordpress. The basic layot is this:

    if (have_posts())
    {
        the_post();
        //print the post
        if (have_posts())
        {
            while (have_posts())
            {
                the_post();
                //print post
                if (have_posts())
                {
                    the_post(); // print post
                }
            }
    }

    Thats basically all. what it should do is show the latest post in the top center. and then show other posts 2 per row.
    The problem is that I have 4 posts for example it shows 1 on the center, 2 posts on a row, and 1 on another row. BUT then it starts showing the latest post once again. So it repeat them once.

    Is it some kind of problem with the loops I made?
    Thanks

  2. Joni
    Member
    Posted 6 years ago #

    http://codex.wordpress.org/The_Loop

    What you want is toward the bottom. You may also want to set up a cat called "Featured" and tell WP to pull the latest post from that category. HTH

  3. blogger_a
    Member
    Posted 6 years ago #

    hi
    thanks for your replay.
    I'm only reading the all posts not any category specific. This is the main (index) page.

    btw everything shows fine when the amount of posts is 3. That is completing the whole row. (1 post in the center) and 2 posts on 1 row...

  4. Adam Brown
    Member
    Posted 6 years ago #

    Try something like this:

    <?php
    $numposts = 0;
    $odd = true;
    if (have_posts()){
      while (have_posts()){
        the_post();
        $numposts++;
        if (1==$numposts){
          // display the first post
        }else{
          // display the rest of the posts
          // check $odd to know whether this is going
          // in the left or right of your two-posts-per-row.
          // after displaying, toggle value of $odd:
          $odd = ($odd) ? false : true;
        }
      }
    }
    ?>
  5. blogger_a
    Member
    Posted 6 years ago #

    thanks that worked :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.