Pagination in a template page? (6 posts)

  1. Debashish
    Posted 9 years ago #

    I created a template as follows:

    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 http://localhost/wordpress/?page_id=77&paged= or http://localhost/wordpress/?page_id=77&paged=1 but when I pass the value of page as 2 as in http://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 ) {
    echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
    next_posts_link($nxtlabel, $max_page);

  2. moshu
    Posted 9 years ago #

    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"?

  3. Debashish
    Posted 9 years ago #

    I would like to have my site something like http://www.uzanto.com/ where the front page is a static page and there are links to various portions like http://www.uzanto.com/blog/ or http://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.

  4. moshu
    Posted 9 years ago #

    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.

  5. Debashish
    Posted 9 years ago #

    Thanks a lot.

  6. suzylavor
    Posted 9 years ago #

    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 http://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.

Topic Closed

This topic has been closed to new replies.

About this Topic