madeinthearcade
2/23/2017 - 10:37 PM

Show recent custom post type posts in 2 loops with an offset

Show recent custom post type posts in 2 loops with an offset

					<?php 
						$args = array( 'post_type' => 'projects', 'posts_per_page' => 1 );
						$the_query = new WP_Query( $args ); 
					?>
					<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
						<?php $featuredImage = wp_get_attachment_image_src( get_post_thumbnail_id($post->id), 'full' ); ?>
						<a href="<?php the_permalink(); ?>" class="flex-item" style="background-image:url( <?php echo $featuredImage[0]; ?> );">
						<div class="ft-work-caption">
							<h2>
								<?php $tags = get_the_tags(); if ( $tags ) : ?>
									<span>
										<?php foreach ($tags as $tag ) {
											echo $tag->name;
										}; ?>
									</span>
								<?php endif; ?>
								<?php the_title(); ?>
							</h2>
							<strong class="view-case-study">
								View case study <i class="fa fa-long-arrow-right" aria-hidden="true"></i>
							</strong>
						</div>
						</a>
					<?php endwhile; wp_reset_postdata(); ?>
						<div class="flex-item">
						<?php $args2 = array( 'post_type' => 'projects', 'posts_per_page' => 2, 'offset' => '1' ); ?>
						<?php $the_query_second = new WP_Query( $args2 ); ?>
						<?php while ($the_query_second->have_posts()) : $the_query_second->the_post(); ?>
							<div class="ft-work-thumbnail">
								<a href="<?php the_permalink(); ?>">
									<?php if ( has_post_thumbnail() ) {
										the_post_thumbnail('full');
										};
									?>
									<div class="ft-work-caption">
										<h2>
											<?php $tags = get_the_tags(); if ( $tags ) : ?>
												<span>
													<?php foreach ($tags as $tag ) {
														echo $tag->name;
													}; ?>
												</span>
											<?php endif; ?>
											<?php the_title(); ?>
										</h2>
										<strong class="view-case-study">
											View case study <i class="fa fa-long-arrow-right" aria-hidden="true"></i>
										</strong>
									</div>
								</a>
							</div>
						<?php endwhile; wp_reset_postdata(); endif; ?>