Create Custom Post Type with WordPress Pagination

Create Custom Post Type with WordPress Pagination

Create custom post type with page pagination in WordPress include add post type with CPT plugin or Custom post type PHP code with create separate template PHP file. Below is the code for guide how to developed.

<?php 
/* 
Template Name: Custom Post with Pagination
*/
?>

<?php get_header(); ?>
 
<main class="add-circle-bg">
    <div class="page-wrap">
     
        <section id="initiatives-page-awar-com-sec">
            <div class="container">
                <?php 
               $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

                $args = array( 'post_type' => 'resource','category_name' => 'notice', 'posts_per_page' => 10, 'paged' => $paged   );

                $the_query = new WP_Query( $args ); 
            ?>

                <?php if ( $the_query->have_posts() ) : ?>
                <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

           
                <!-- press circular report -->
                <div class="row ">
                    <div class="col-md-12">
                         <div class="ipac-b-h-p text-small"><?php the_title(); ?></div>
                    </div>
                </div>

                <!-- press circular report -->
       
                <?php endwhile; ?>
                         <?php
 
                            global $the_query;  

                              $total_pages = $the_query->max_num_pages;  
                               if ($total_pages > 1){  
                                $current_page = max(1, get_query_var('paged'));  
                            echo '<div class="page-numbers-centered tender-closed-list">';
                            echo paginate_links(array(  
                              'base' => get_pagenum_link(1) . '%_%',  
                              'format' => '/page/%#%',  
                              'current' => $current_page,  
                              'total' => $total_pages,
                              'type' => 'list',
                              'prev_text' => '<<',
                              'next_text' => '>>',
                            )); 

                            echo '</div>';
                        } 

                        ?>
                       <?php wp_reset_postdata(); ?>
                            <?php else:  ?>
                            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
                            <?php endif; ?>
            </div>
        </section>
        <?php get_template_part( 'templates/content', 'want_part_team');?>
    </div>
    <!-- page wrap-->
</main>
<?php get_footer(); ?>        


ujwala Bhagat

Assistant Professor in AI and DS department

6 个月

Great advice ok

赞
回复

要查看或添加评论,请登录

Rajvinder Singh的更多文章

社区洞察

其他会员也浏览了