Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress Offset
<?php get_header(); ?>
<?php
$number_of_feature_posts = 1;
$number_of_secondary_posts = 8;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$how_many_secondary_posts_past = ($number_of_secondary_posts * ($paged - 1));
$off = $number_of_feature_posts + (($paged > 1) ? $how_many_secondary_posts_past : 0);
?>
<div class="row main-content post-content">
<div class="small-16 medium-16 large-18 small-centered columns">
<div class="latest">
<?php
$args = array(
'posts_per_page' => $number_of_feature_posts,
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-quote'),
'operator' => 'NOT IN'
)
),
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
if (false == get_post_format()) { ?>
<h1 class="text-center post-title"><a href="<? the_permalink(); ?>"><?php the_title(); ?></a></h1>
<div class="post-meta text-center">
<p class="author">By <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author_meta('display_name'); ?></a></p>
</div>
<?php if ( has_post_thumbnail() ) : ?>
<div class="featured-image">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Continue reading <span class="meta-nav">&rarr;</span></a></p>
<?php } else {
get_template_part( 'content', get_post_format() );
}
endwhile;
wp_reset_query();
?>
</div>
<div class="row">
<div class="small-18 medium-11 small-centered medium-uncentered columns">
<div class="post-listing">
<?php
$args = array(
'posts_per_page' => $number_of_secondary_posts,
'offset' => $off,
'showposts' => $number_of_secondary_posts
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; wp_reset_query();
?>
</div>
<div class="navigation">
<div class="left"><?php next_posts_link('&larr; Older Entries') ?></div>
<div class="right"><?php previous_posts_link('Newer Entries &rarr;') ?></div>
</div>
</div>
<div class="small-18 medium-5 columns medium-offset-2 small-centered medium-uncentered">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.