Last active
November 13, 2017 15:18
-
-
Save yuriitaran/5a994cf5a3c7c62c07fce78de5c43656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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