WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Wrapping 4 posts in a two divs (1 post)

  1. mikelawton86
    Member
    Posted 7 months ago #

    HI,

    I'm trying to wrap 4 individual posts with a category id of 3 into two individual divs i.e

    <div class="postContainer">
    POST1
    POST2
    POST3
    POST4
    </div>

    <div class="postContainer">
    POST5
    POST6
    POST7
    POST8
    </div>

    Am i right in thinking that this should work:

    <?php query_posts('cat=3'); ?>
    
    <?php while( have_posts() ) : the_post(); //start of the loop ?>
    
    <?php if( $wp_query->current_post%4 == 0 ) echo "\n".'<div class="postContainer clearfix">'."\n"; ?>
    <div class="postDivider">
    
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    	<div class="date"><?php the_time('m.d.Y'); ?></div>
    
    	<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    	<div class="featured-post">
    	<?php _e( 'Featured post', 'twentytwelve' ); ?>
    	</div>
    	<?php endif; ?>
    	<header class="entry-header">
    	<a href="<?php the_permalink(); ?>"><img src="<?php the_field('homepage_image'); ?>" /></a>
    	<?php if ( is_single() ) : ?>
    	<h1 class="entry-title"><?php the_title(); ?></h1>
    	<?php else : ?>
    	<h1 class="entry-title">
    	<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
    	</h1>
    	<?php endif; // is_single() ?>
    
    	</header>
    
    	<?php if ( is_search() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    	<?php the_excerpt(); ?>
    	</div>
    	<?php else : ?>
    	<div class="entry-content">
    	<?php // the_content('Read on...'); ?>
    	<?php the_excerpt(); ?>
    
    	<?php $this_post = $post->ID ?>
    	<?php the_secondary_content('Excerpt', $this_post); ?>
    
    	<a class="permalink" href="<?php the_permalink(); ?>">MORE ></a>
    
    	<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    
    	<div class="thelinks"><a href="?page_id=13">FASHION</a> / <a href="?page_id=11">TRAVEL</a> / <a href="?page_id=10">VIDEOS</a></div>
    
    	<div class="socialmedia clearfix mAuto">
    	<a class="addthis_button_twitter"></a>
    	<a class="addthis_button_facebook"></a>
    	<a class="addthis_button_pinterest_pinit"></a>
    	</div>
    	</div>
    	<?php endif; ?>
    
    	</article>
    
    </div>
    <?php if( $wp_query->current_post%4 == 3 || $wp_query->current_post == $wp_query->post_count-1 ) echo '</div>'."\n"; ?>
    <?php endwhile; //end of the loop ?>

    Thanks in advance.

Reply

You must log in to post.

About this Topic