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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:34:50+00:00 2026-06-12T15:34:50+00:00

I have this loop which basically displays a block on the page with an

  • 0

I have this loop which basically displays a block on the page with an image in it, the class gallerypic has a margin of 20px on the right, it also has the rule float:left;, the issue is every time the third div is created it starts on a new line, because the margin is pushing it there. So Ideally every third post I would like no margin, and to apply a div gallerypicright or something.

Im wondering does someone have a solution to this? Possibly an easier one that simply stops the margin from happening when its the third one? I need the margin on the other two as it creates a neat gap between the posts.

<?php 
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $archive_query = new WP_Query('cat=14&showposts=14&paged=' . $paged);
            $id = get_the_ID();

while ($archive_query->have_posts()) : $archive_query->the_post(); ?>

                     <div class="events">
        <div class="gallerypic"><div class="limerickguideblockheader"><p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?>
        </div>
        <div class="gallerypiccontainer"><a href="<?php the_permalink(); ?>" >
         <?php echo get_the_post_thumbnail( $id, 'gallery-thumb', $attr ); ?> </a></div>
         </div> 
  </div>
            <?php endwhile; ?>

edit: a picture paints a 1000 words, here is the link so far, with three posts…
http://limerickfc.hailstormcommerce.com/cms/?page_id=2466

A method via CSS would be even better if possible.
Cheers
Adrian

  • 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-12T15:34:51+00:00Added an answer on June 12, 2026 at 3:34 pm

    Try the below code.

    <style>
    .gallerypicright {
      margin: 0;
    }
    </style>
    ...
    <?php
    $count = 0;
    while ($archive_query->have_posts()) : $archive_query->the_post(); 
      $count++;
      $third_div = ($count%3 == 0) ? 'gallerypicright' : '';
    ?>
    ...
    <div class="gallerypic <?php echo $third_div; ?>">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically i am reading image bytes from file i have a loop which has
I have a loop which basically calls this every few seconds (after the timeout):
I have this class in which I run a for loop 10 times. This
I have a problem here, Basically. . I have a loop which has a
In my code, I have this loop, which brings up various 2-hour time blocks.
Possible Duplicate: php loop through associative arrays i have this piece of code which
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,
Hi I have this code below which basically after 25 seconds of showing the
I'm developing this time container which basically contains instances of a class called week,
I have this loop method to display a ViewPager and I set an OnClickListener

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.