Numeric pagination custom post type
Question
i create a custom page to display loop of cpt with custom field.
I need to add a numberic pagination and i try with this code but not work.
Functions.php
function pagination_bar() {
global $wp_query;
$total_pages = $wp_query->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,
));
}
}
custompage.php
<!--Loop Salmi-->
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$loop = new WP_Query( array( 'post_type' => 'salmi',
'posts_per_page' => 15,
'paged' => $paged )
);
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<!--Colonne Contenuto -->
<div class="salmicpt">
<div class="wpb_column vc_column_container td-pb-span8">
<div class="titlecpt"><?php the_title(); ?></div>
</div>
<div class="wpb_column vc_column_container td-pb-span4">
<?php if( get_field('audio_salmi') ): ?>
<a href="<?php the_field('audio_salmi'); ?>" ><img src="mysite.com/wp-content/uploads/cuffia-cpt-e1481533293805.png" alt="Ascolta" title="Ascolta" /></a>
<?php endif; ?>
<?php if( get_field('salmi_pdf') ): ?>
<a href="<?php the_field('salmi_pdf'); ?>" ><img src="mysite.com/wp-content/uploads/freccia-32.png" alt="Scarica il PDf" title="Scarica il PDF" /></a>
<?php endif; ?>
</div>
<div style='clear:both'></div><hr class="style-one" />
</div>
<nav class="pagination">
<?php pagination_bar(); ?>
</nav>
<?php endwhile; wp_reset_query(); ?>
Where is wrong?? Thanks
0
custom-post-types, pagination, wp-query, wp-reset-query
3 years
2020-03-31T00:51:16-05:00
2020-03-31T00:51:16-05:00 0 Answers
89 views
0
Leave an answer