$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to use pagination on costum post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to use pagination on costum post type

matteradmin9PV0评论

i made a costum post type use plugin Costum post type UI

and i tried to display i on homepage / index

code

<?php args1 = array( 'post_type' => 'app', 'posts_per_page' => 3 );$the_query1 = new WP_Query( $args1 );
// The Loop
if ( $the_query1->have_posts() ) {
while ( $the_query1->have_posts() ) : $the_query1->the_post(); ?>
    <h1><a href="<?php the_permalink();?>"><?php the_title();?></a></h1>
    <?php
endwhile;
wp_reset_postdata();
} else {
echo "no post found"; }?>

so , how to display the pagination ??

thank's

*sory my bad english

i made a costum post type use plugin Costum post type UI

and i tried to display i on homepage / index

code

<?php args1 = array( 'post_type' => 'app', 'posts_per_page' => 3 );$the_query1 = new WP_Query( $args1 );
// The Loop
if ( $the_query1->have_posts() ) {
while ( $the_query1->have_posts() ) : $the_query1->the_post(); ?>
    <h1><a href="<?php the_permalink();?>"><?php the_title();?></a></h1>
    <?php
endwhile;
wp_reset_postdata();
} else {
echo "no post found"; }?>

so , how to display the pagination ??

thank's

*sory my bad english

Share Improve this question asked Jan 20, 2019 at 3:27 saulsaul 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type'=>'post', // Your post type name
'posts_per_page' => 6,
'paged' => $paged,); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post(); // YOUR CODE
endwhile;
$total_pages = $loop->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'    => __('« prev'),
        'next_text'    => __('next »'),
    ));
}} wp_reset_postdata();

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far