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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:06:16+00:00 2026-05-22T21:06:16+00:00

I would like to have a specific divider after my posts. I have 3

  • 0

I would like to have a specific divider after my posts.

I have 3 dividers -> divider1,divider2,divider3

Basicly i would like for them to loop, so after post 1 i get divider1, post 2-> divider2, post3->divider3, post 4 ->divider1 etc…

This is my code:

<div class="post">
              <div class="post-title">
                  <h2><a href="<?php the_permalink() ?>" rel="bookmark"
                         title="Permanent Link to  <?php the_title_attribute(); ?>">
                      <?php the_title(); ?>
                  </a></h2>
              </div>
              <div class="post-date">
                  <?php the_time('j-n-Y') ?><br/>
              </div>

              <div class="entry">
                  <?php the_excerpt();?>
              </div>
              <div class="meta">
                  <span class="post-cat"><?php the_category(',') ?></span>
                  <span class="post-comments"> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
              </div>
              <div class="divider1"></div>
          </div>

so the class should loop from divider1 to divider2 to divider3 to divider1 and keep on looping, can anyone help me?

  • 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-05-22T21:06:17+00:00Added an answer on May 22, 2026 at 9:06 pm

    Make a counter and check its modulus to cycle 1 to 3 (actually we’ll use 0 to 2)

    // Start counter at 0
    $counter = 0;
    // This is your loop
    foreach ($posts as $post) {
    
      // Now a switch will determine which divider to use.
      // We'll select class divider1 divider2 or divider3 based 
      // on the current counter position. This will keep looping no
      // matter how many posts you have
      switch ($counter % 3) {
        case 0: // output divider 1
          $divider_class = 'divider1';
          break;
        case 1: // output divider 2
          $divider_class = 'divider2';
          break;
        case 2: // output divider 3
          $divider_class = 'divider3';
          break;
      }
    
      // All your HTML is output here...
      // Skipping most of it for brevity, but the important part is the divider...
      <div class="<?php echo $divider_class;?>"></div>
    
      // EDIT Forgot the important step of incrementing the counter...
      $counter++;
    
    // Don't forget to close your loop
    }
    

    There are other ways you could do this. For example, without the switch you can set the divider class directly with the modulus:

    // Alternate method - no switch and less typing but less flexible
    $divider_class = "divider" . ($counter % 3);
    
    <div class="<?php echo $divider_class;?>">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a specific DB2 query, and I would like to execute this query
I have a string in C# and would like to get text from specific
I have a DataGridView that I would like all values on a specific row
I have a specific case here in which I would like some security advice.
I would like to make all .note elements have a specific tooltip. Is it
I would like to have a specific layout but don't know how to fix
I would like to have my base URL go to a specific category of
I would like to get all form elements that don't have a specific CSS
I have two specific fonts installed on my computer and would like to configure
I would like to have my Sinatra app include a view specific stylesheet in

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.