WordPress.org

Forums

[resolved] Pagination doesn't work on custom blog page (9 posts)

  1. ecko00920
    Member
    Posted 1 year ago #

    hi!
    my website's blog page's pagination won't work and i don't know why, my blog page is set to show only 9 posts, i have more than 9 posts already but the pagination won't work, if anyone could help me please!
    here's my blog page code:

    <?php
                     $blog_page = new WP_query();
                        $blog_page->query('showposts=9');
                        while($blog_page->have_posts()) : $blog_page->the_post();
    
                    ?>

    here's my blog page's link:
    http://firstsnowph.net/home/data/

  2. vtxyzzy
    Member
    Posted 1 year ago #

    You will need to add the 'paged' parameter to your WP_Query() call and also modify the next_posts_link() call. See this Codex article for an example: http://codex.wordpress.org/Function_Reference/next_posts_link#Usage_when_querying_the_loop_with_WP_Query

  3. ecko00920
    Member
    Posted 1 year ago #

    can you help me do that?

    here's my full code:

    <?php
    /*
    Template Name: Blog Page
    */
    ?>
    
    <?php get_header(); ?>
      <div id="primary_box">
    
                    <?php
                     $blog_page = new WP_query();
                        $blog_page->query('showposts=9');
                        while($blog_page->have_posts()) : $blog_page->the_post();
    
                    ?>
    
                    <div class="post_box">
                            <div class="post_padding">
                                <h1><a href="<?php the_permalink();?>"><?php the_title();?></a></h1>
                                <p class="metadata">
                                    <?php echo word_count(get_the_excerpt(), '30'); ?>
                                </p>
                                <p><a class="more-link floatright" href="<?php the_permalink();?>">Read More</a></p>
                            </div>
    
                    </div>
    
                    <?php endwhile; ?>
                </div>
    <div align="center">
    <?php wp_pagenavi(); ?>
    </div>
    <?php get_footer(); ?>

    the page i'm modifying is here: http://firstsnowph.net/home/data/

    it would be really a great help, i can't figure out how i will add the parameters coz i'm still noob with this :/

  4. vtxyzzy
    Member
    Posted 1 year ago #

    I can't test this, but it should be close:

    <?php
    /*
    Template Name: Blog Page
    */
    ?>
    
    <?php get_header(); ?>
       <div id="primary_box">
    
          <?php
             $paged = ($_GET('paged')) ? $_GET('paged') :
                   (($_GET('page')) ? $_GET('page') : 1 );
             $blog_page = new WP_query();
             $blog_page->query("showposts=9&paged=$paged");
             while($blog_page->have_posts()) : $blog_page->the_post();
    
             ?>
    
                <div class="post_box">
                   <div class="post_padding">
                      <h1><a href="<?php the_permalink();?>"><?php the_title();?></a></h1>
                      <p class="metadata">
                         <?php echo word_count(get_the_excerpt(), '30'); ?>
                      </p>
                      <p><a class="more-link floatright" href="<?php the_permalink();?>">Read More</a></p>
                   </div>
    
                </div>
    
          <?php endwhile; ?>
       </div>
    <div align="center">
    <?php wp_pagenavi( array( 'query' => $blog_page ) ); ?>
    </div>
    <?php get_footer(); ?>
  5. ecko00920
    Member
    Posted 1 year ago #

    hi! thank you so much for helping i really appreciate your kindness for helping, though when i tried your fix all the posts disappear :/

  6. vtxyzzy
    Member
    Posted 1 year ago #

    Please replace this:

    $paged = ($_GET('paged')) ? $_GET('paged') :
                   (($_GET('page')) ? $_GET('page') : 1 );

    with this:

    $paged = ($_GET['paged']) ? $_GET['paged'] :
                   (($_GET['page']) ? $_GET['page'] : 1 );
  7. ecko00920
    Member
    Posted 1 year ago #

    thank you so much! the pagination is okay now! it's working, but why do when i click the next page the posts showing are still the one on first page, i think it doesnt go to page 2?

  8. vtxyzzy
    Member
    Posted 1 year ago #

    I am so terribly sorry! I am just not thinking clearly. Please try this for setting $paged:

    $paged = (get_query_var('paged')) ? get_query_var('paged') :
                   ((get_query_var('page')) ? get_query_var('page') : 1 );
  9. ecko00920
    Member
    Posted 1 year ago #

    thank you much for helping! it's all working now! thank you so much for helping me fix this! you're so great! ^_^
    thank you vtxyzzy for resolving my problem ^_^

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags