• I created a template as follows:

    <?php
    /*
    Template Name: Test
    */
    ?>
    <?php get_header(); ?>
    <?php $my_query = new WP_Query('category_name=Post&paged='.$q['paged']); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <h5><a href="<?php the_permalink()?>" class="posttitle"><?php the_title(); ?></a></span></h5>
    By <?php the_author()?>, on <?php the_time('M jS, y')?>
    <?php the_excerpt(); ?>
    <a>">Continue reading...</a>
    <?php endwhile; ?>
    <?php get_nav_link(7) ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I create a custom page based on this template and want that a limited number of posts appear on this page and pagination links appear at bottom.

    The page works fine when I call the page as https://localhost/wordpress/?page_id=77&paged= or https://localhost/wordpress/?page_id=77&paged=1 but when I pass the value of page as 2 as in https://localhost/wordpress/?page_id=77&paged=2, the index.php page comes into play (though there are more posts in the category ‘Post’).

    Can anyone please help me with what is preventing the pagination?

    PS. get_nav_link() is a customized function based on the posts_nav_link() function and accepts the category code as parameter.

    function get_nav_link($cat, $sep=' — ', $prelabel='? Previous Page', $nxtlabel='Next Page ?') {
    global $request, $posts_per_page, $wpdb, $max_num_pages;
    if ( !is_single() ) {
    if ( 'posts' == get_query_var('what_to_show') ) {
    if ( !isset($max_num_pages) ) {
    $numposts = $wpdb->get_var("SELECT COUNT( DISTINCT a.ID ) FROM wp_posts a, wp_post2cat b WHERE a.ID = b.post_id AND b.category_id = $cat");
    $max_num_pages = ceil($numposts / $posts_per_page);

    }
    }
    else {
    $max_num_pages = 999999;
    }

    if ( $max_num_pages > 1 ) {
    previous_posts_link($prelabel);
    echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
    next_posts_link($nxtlabel, $max_page);
    }
    }
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • Because it is a Page.
    1. Pages are not supposed to display more than one “content”.
    2. Pages don’t have “pagination”.

    What exactly are you trying to achieve with this “Page”?

    Thread Starter Debashish

    (@debashish)

    I would like to have my site something like https://www.uzanto.com/ where the front page is a static page and there are links to various portions like https://www.uzanto.com/blog/ or https://www.uzanto.com/articles/. These are nothing but pages based on template and show a limited number of posts belonging to a particular category.

    Exactly what I need, the only thing missing is pagination.

    Never understood why is everybody “obsessed” by Pages for tasks that are not normally feasable with Pages? What you want to do is already solved out of the box by WP – just by using Category_Templates.

    Thread Starter Debashish

    (@debashish)

    Thanks a lot.

    Hello, please i would like to know if it is not possible pagination on a Page? My blog is like a template shop, so have many stuff to add. Take a look at https://www.templates4you.org at link “Acessorios” and “Alfabetos”. I have too many alphabets…how do i use Php without pagination? Do i have to create pages to each ones? PS.:sorry my english is not very good. Thanks a lot for you help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pagination in a template page?’ is closed to new replies.