Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:39:33+00:00 2026-06-11T17:39:33+00:00

I am working on a wordpress site where I need every other post in

  • 0

I am working on a wordpress site where I need every other post in a category to have a different layout.

Meaning, the first post will have image on the left, text on the right. The next post will have text on the left, image on the right. The next post (3rd post) will be back to image on the left, text on the right, and so on.

Ignore the coding because it was just a quick one, but here is a jfiddle that visually shows the effect I want. http://jsfiddle.net/U4amd/

I have figured out how to layout “even” posts one way and “odd” posts differently, but used two loops to accomplish it. This won’t work though because then all the even posts are showed followed by all of the odd. Here is the code I currently have:

`

        <?php while(have_posts()) : ?>
        <?php
            $postcount++;
            if( ($postcount % 2) == 0 ) : // skip 'even' posts
                $wp_query->next_post();
            else :
        ?>
        <?php the_post(); ?>

    <div class="product clearfix color-box">

        <div class="vendor pRight fleft">
            <?php $color = get_post_meta($post->ID, 'color', true) ?>
            <div class="color-box-expand pad-inside" style="background-color:<?php echo $color; ?>">
                <?php the_post_thumbnail('bones-thumb-vb'); ?>
            </div>
        </div>
        <div class="vendor-images fleft">
            <?php $slide01 = get_post_meta($post->ID, 'slide01', true) ?>
            <img src="<?php echo $slide01 ?>">  
            <?php the_content() ?>
        </div>

    </div>

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

    <?php $postcount = 0; rewind_posts(); ?>

        <?php while(have_posts()) : ?>
        <?php
            $postcount++;
            if( ($postcount % 2) != 0 ) : // skip 'odd' posts
                $wp_query->next_post();
            else :
            ?>
        <?php the_post(); ?>

    <div class="product clearfix color-box">

        <div class="vendor-images fleft">
            <?php $slide01 = get_post_meta($post->ID, 'slide01', true) ?>
            <img src="<?php echo $slide01 ?>">  
            <?php the_content() ?>
        </div>

        <div class="vendor pLeft fleft">
            <?php $color = get_post_meta($post->ID, 'color', true) ?>
            <div class="color-box-expand pad-inside" style="background-color:<?php echo $color; ?>">
                <?php the_post_thumbnail('bones-thumb-vb'); ?>
            </div>
        </div>

        <?php endif; ?>
        <?php endwhile; ?>
    </div>
</div>`

Any help at all would be really appreciated. I’m new to php/Wordpress, so still figuring everything out. And if I need to clarify anything just let me know. Thanks!


@Crowjonah — putting this here cause i went over the character limit in a comment —
I probably didn’t do something right, but now when looking at the code in firebug, there are no .even classes assigned. Here is my code based on the above.

<?php $postcount=0;
            while(have_posts()) :        
                $postcount++;
                if( ($postcount % 2) == 0 ) $post_class = ' even';
                else $post_class = ' odd'; ?>
                <div class="product clearfix color-box">                    
                    <div class="vendor pRight <?php echo $post_class; ?>">
                        <?php the_post(); ?>
                        <?php $color = get_post_meta($post->ID, 'color', true) ?>
                        <div class="color-box-expand pad-inside" style="background-color:<?php echo $color; ?>">
                            <?php the_post_thumbnail('bones-thumb-vb'); ?>
                        </div>
                    </div>
                    <div class="vendor-images post <?php echo $post_class; ?>">
                        <?php $slide01 = get_post_meta($post->ID, 'slide01', true) ?>
                        <img src="<?php echo $slide01 ?>">  
                        <?php the_content() ?>
                    </div>
                </div>

        <?php $postcount++;
            endwhile; ?>

Thanks so much for your help man.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:39:35+00:00Added an answer on June 11, 2026 at 5:39 pm

    You can use the same incrementing and detecting you have in your two loops, but consolidate it into one loop that assigns a corresponding even or odd class to your post wrapper:

    <?php 
        $postcount=1;
        while(have_posts()) :        
            if( ($postcount % 2) == 0 ) $post_class = ' even';
            else $post_class = ' odd'; ?>
            <div class="post <?php echo $post_class; ?>">            
                <?php the_post(); ?>
            </div>
    <?php 
            $postcount++;
        endwhile; 
    ?>
    

    Using CSS, you can then assign

    div.post.even img {
       float: left; /* etc etc */
    }
    div.post.odd img {
       float: right; /* etc etc */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a WordPress site and I have placed the following code
I'm working on a wordpress site, with a blog post that ends like: http://www.blog.com/?p=2
I'm working on a WordPress that will allow the site administrator to switch between
I have a wordpress site that i've been working on that has some pages
I have a Wordpress site that I am currently working on and have set
i'm working on my first WP site and need to display an author's role
I am working on a wordpress site, and I have downloaded a plugin called
I have just installed a custom WordPress theme (this is my first time working
I'm working on fixing a wordpress site that's very slow. I need a way
I am working on a wordpress site and I need some overlay windows. They

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.