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 8612331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:36:00+00:00 2026-06-12T04:36:00+00:00

I have a WordPress loop as follows: <?php $loop = new WP_Query( array( ‘post_type’

  • 0

I have a WordPress loop as follows:

<?php $loop = new WP_Query( array( 'post_type' => 'portfolio' ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="four columns">
        <?php the_content(); //along with other stuff in looped div ?>
    </div>
<?php endwhile ?>

How can I add an ‘alpha’ class to every (4n-3)th div (div.four.columns) and an ‘omega’ class to every (4n)th item using php?

Thanks (a lot!),
Jamie

  • 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-12T04:36:01+00:00Added an answer on June 12, 2026 at 4:36 am

    Why not add a counter and use the modulus approach to get to know in every column what element you are currently echoing.

    Lets say you have 4 columns as specified.
    You start with counter = 1
    1 % 4 = 1 ( you are in the first element )
    2 % 4 = 2 ( you are in the second element )
    3 % 4 = 3 ( you are in the third element )
    4 % 4 = 0 ( you are in the fourth element )
    5 % 4 = 1 ( you are in the first element )
    6 % 4 = 2 ( you are in the second element )

    And you just use an If statement with the class as following

    <?php $counter = 1 ?>
    <?php $loop = new WP_Query( array( 'post_type' => 'portfolio' ) ); ?>
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <div class="four columns <?php if ($counter % 4 == 1){echo 'alpha'}else if ($counter % 4 == 0){echo 'omega'} ?>">
            <?php the_content(); //along with other stuff in looped div ?>
        </div>
    <?php $counter++ ; 
    endwhile ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Wordpress loop: while ( $query->have_posts() ) : $query->the_post(); echo'<h3><a href=index.php?page_id=100>';the_title(); echo'</a></h3>';
In wordpress, I have the loop.php file. There I can see the 'read more'
Although I have experience with PHP, WordPress is pretty new to me and I
I have a wordpress loop that pulls all of my data from a table...
i have a wordpress based website. I have a standard wordpress loop that executes
I have the following code in my wordpress loop to display sticky posts: <div
I have made a custom loop in WordPress and for some reason, the date
How to Get page permalink and title outside the loop in wordpress. I have
I am using the Wordpress Loop. I then have a modal popup with more
I have written a loop in wordpress that loops through the post titles and

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.