Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriitaran/5a994cf5a3c7c62c07fce78de5c43656 to your computer and use it in GitHub Desktop.
Save yuriitaran/5a994cf5a3c7c62c07fce78de5c43656 to your computer and use it in GitHub Desktop.
/* functions.php */
// Create pagination
function foundation_pagination( $query = '' ) {
if ( empty( $query ) ) {
global $wp_query;
$query = $wp_query;
}
// required for static front-page pagination
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
// required for static front-page pagination
$big = 999999999;
$links = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_next' => true,
'prev_text' => '«',
'next_text' => '»',
'current' => max( 1, $paged ),
'total' => $query->max_num_pages,
'type' => 'list'
) );
$pagination = str_replace( 'page-numbers', 'pagination', $links );
echo $pagination;
}
/* template-homepage.php */
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'post',
'order' => 'ASC',
'posts_per_page' => 4,
'paged' => $paged
);
$the_query = new WP_Query( $query_args );
if ( $the_query->have_posts() ) : ?>
<div class="articles">
<div class="row columns">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article class="large-3 medium-6 small-12 column article">
<h2><?php the_title(); ?></h2>
<?php the_content( $more_link_text , $strip_teaser ); ?>
</article>
<?php endwhile; ?>
</div>
<div class="row columns pagination"><?php echo foundation_pagination($the_query); ?></div>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment