WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Homepage pagination (2 posts)

  1. carbonmadex
    Member
    Posted 3 years ago #

    When the blog posts are called in a custom page template with the below code the pagination works just fine:

    <?php global $paged;
    
    $bcat = get_option('of_blog_category');
    $bcatid = get_cat_id($bcat);
    
    query_posts(array(
    'cat'=>$bcatid,
    'posts_per_page' => 9,
    'paged' => $paged
    )); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    

    However when I set the page which uses this template as my homepage in "Settings - Reading", the pagination stops working.

    What may be the reason for this? How can I solve it?

  2. carbonmadex
    Member
    Posted 3 years ago #

    Well I solved the issue by replacing the above code with this:

    <?php
    $bcat = get_option('of_blog_category');
    $bcatid = get_cat_id($bcat);
    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
    } else {
    $paged = 1;
    }
    query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'cat'=> $bcatid, 'posts_per_page' => 9 ) );
    ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic