Created
May 13, 2020 17:25
-
-
Save sooraj771989/6e9d097b2a6d21ef72946be7c735b95a 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
<div class="max-w-xl px-5 py-12 mx-auto"> | |
<div class="text-center w-full"> | |
<h1 class="uppercase font-black text-3xl md:text-5xl py-4 md:py-8">Latest Posts</h1> | |
</div> | |
<?php global $query_string; query_posts($query_string . '&posts_per_page=3'); ?> | |
<?php | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$data= new WP_Query(array( | |
'post_type'=>'post', | |
'posts_per_page' => 3, // post per page | |
'paged' => $paged, | |
)); | |
if($data->have_posts()) : | |
while($data->have_posts()) : $data->the_post(); ?> | |
<?= partial('post-list'); ?> | |
<?php endwhile; ?> | |
<div class="pagination text-center w-full"> | |
<?php | |
$total_pages = $data->max_num_pages; | |
if ($total_pages > 1){ | |
$current_page = max(1, get_query_var('paged')); | |
echo paginate_links(array( | |
'base' => get_pagenum_link(1) . '%_%', | |
'format' => '/page/%#%', | |
'current' => $current_page, | |
'total' => $total_pages, | |
'prev_text' => __('Previous'), | |
'next_text' => __('Next'), | |
)); | |
} | |
?> | |
</div> | |
<?php else :?> | |
<h3><?php _e('404 Error: Not Found', ''); ?></h3> | |
<?php endif; ?> | |
<?php wp_reset_postdata();?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment