paginacja custom post WordPress
tworzenie pętli custom wpisów z podziałem ich wykazu na strony:
<?php $args = array( 'post_type' => 'event',
'posts_per_page' => 16,
'orderby' => 'post_date',
'order' => 'DESC'
);
// query
$wp_query = new WP_Query( $args );
// start loop
while( $wp_query->have_posts()) : $wp_query->the_post(); ?>
<div><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
<?php // stop and reset loop endwhile; wp_reset_query(); ?>
–
lub:
<ul>
<?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; $args = array( 'post_type' => 'event',
'posts_per_page' => 12,
'meta_key' => 'customer',
'orderby' => 'meta_value',
'order' => 'ASC',
'paged' => $paged
);
// query
$wp_query = new WP_Query( $args );
// loop
while( $wp_query->have_posts() )
{
$wp_query->the_post(); ?>
<li><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
</ul>
–
lub przez pobranie nazwy custom post z paska adresu:
<?php $query_params = getQueryParams(); $query_params['post_per_page'] = 8; $wp_query = new WP_Query($query_params); while($wp_query->have_post()):
$wp_query->the_post();
?>
<li><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
–
oraz sama paginacja, z pobraniem maksymalnej ilości stron aby nie przejść do nie istniejących już stron:
<a href="<?php echo previous_post(true); ?>" class="nav-left"><</a> <a href="<?php echo next_post($wp_query->max_num_pages, true); ?>" class="nav-right">></a>
–
Hope this helps and happy coding :)
Zobacz jeszcze
lista kategorii custom post
pobranie listy category name & link custom post <?php $args = array( 'taxonomy' => 'my-category', 'orderby' => 'name', 'order' => 'ASC', 'show_count'...