Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WordPress Pagination Code to Display Page Pagination in Custom Post Type
#1
Hello, Guys.

Today I am going to share the code which helps you to add number type pagination to your custom type blog post listing template page. All you want to do, Create a page called pagination.php in page-templates folder and copy the given code to it. After that call the page using include function to your custom type post listing page in page-template folder.

PHP Code:
 <?php

    $big
=100;

 
    echo paginate_links(array(

 
       'base' => str_replace$big'%#%'esc_urlget_pagenum_link$big ) ) ),

 
       'format' => '?paged=%#%',

 
       'current' => max1$pge ),

 
       'total' => $total,

 
       'prev_text'    => __('<i class="fa fa-caret-left"></i>'),

 
       'next_text'    => __('<i class="fa fa-caret-right"></i>'),

 
   ) ); ?>


            <?php wp_reset_postdata(); ?>



<script>

jQuery(document).ready(function(){

    jQuery('.paging-navigation a').each(function(){

        a=jQuery(this);

        href=a.attr('href');

        href_or=a.attr('href');

        href=href.split('/');

        if(href[7]==1){

        if(href[4]=="ar"){new_href= href_or.replace("/page/1","");

        a.attr('href',new_href);}}

    })

})

</script> 

You can call the pagination code by using the include in PHP. Like the below example.

PHP Code:
            <?php

            $news_args 
= array(

                    
'post_type' => "college_directory",

                    
'post_status' => "publish",

                    
'orderby' => 'menu_order',

                    
'posts_per_page' => 1,

                    
'paged' => $paged,

                    
'order' => 'ASC'

            
);

            
$my_query = new WP_Query($news_args);

            if (
$my_query->have_posts()) {

                    while (
$my_query->have_posts()) {

                            
$my_query->the_post(); ?>
                    <div class="media">
                        <div class="media-left media-middle">
                                <a href="<?php the_permalink(); ?>">
                                <div><?php   the_post_thumbnail( array(6565))?></div>
                                </a>
                            </div>
                            <div class="media-body">
                                <h4 class="media-heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                    <p class="media-p"><?php the_excerpt(); ?></p>
                            </div>
                    </div>
                    <?php

                
$total $my_query->max_num_pages;

                    
$pge get_query_var('paged');

                    include 
'pagination.php';

            } else {

                    echo 
'No institutions to display';

            }

            
?>

On the above page, you can see that by using include I called the pagination.

If you have any doubts, Just comment.

Thnaks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)