Viewing 2 replies - 1 through 2 (of 2 total)
  • you can use php incrementing operators with your wp loop, just play with it until you reach your goal.

    here is an example

    php code

    <div id="gridcontainer">
    <?php
    $counter = 1; //start counter
    
    $grids = 2; //Grids per row
    
    global $query_string; //Need this to make pagination work
    
    /*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
    query_posts($query_string . '&caller_get_posts=1&posts_per_page=12');
    
    if(have_posts()) :	while(have_posts()) :  the_post();
    ?>
    <?php
    //Show the left hand side column
    if($counter == 1) :
    ?>
    			<div class="griditemleft">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    				</div>
                    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    <?php
    //Show the right hand side column
    elseif($counter == $grids) :
    ?>
    <div class="griditemright">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    				</div>
                    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    <div class="clear"></div>
    <?php
    $counter = 0;
    endif;
    ?>
    <?php
    $counter++;
    endwhile;
    //Pagination can go here if you want it.
    endif;
    ?>
    </div>

    css code

    #gridcontainer{margin: 20px 0; width: 100%; }
    #gridcontainer h2 a{color: #77787a; font-size: 13px;}
    #gridcontainer .griditemleft{float: left; width: 278px; margin: 0 40px 40px 0;}
    #gridcontainer .griditemright{float: left; width: 278px;}
    #gridcontainer .postimage{margin: 0 0 10px 0;}

    you can do this without further editing the loop.php;

    assuming your theme uses post_class() https://codex.wordpress.org/Function_Reference/post_class in the container for each post in the loop, you can add alternating CSS classes to the posts in the loop by adding a filter function to functions.php (of your child theme);

    example code:

    add_filter( 'post_class', 'alternating_post_classes' );
    function alternating_post_classes( $classes ) {
      global $wp_query;
      $classes[] = ( $wp_query->current_post%2 == 0 ? 'first-left' : 'second-right' );
      return $classes;
    }

    and the CSS for the images would be:

    .first-left a.artikelbild img { float: left; }
    .second-right a.artikelbild img { float: right; }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘two different loops to align images needed’ is closed to new replies.