Support » Themes and Templates » Strange problem

  • blogger_a

    (@blogger_a)


    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • jonimueller

    (@jonimueller)

    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

    Thread Starter blogger_a

    (@blogger_a)

    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…

    Adam Brown

    (@adamrbrown)

    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;
        }
      }
    }
    ?>
    Thread Starter blogger_a

    (@blogger_a)

    thanks that worked 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Strange problem’ is closed to new replies.