• Resolved kikimarie123

    (@kikimarie123)


    I’m stumped. I’ve read through a ton of other posts but can’t find a solution. My page navigation just won’t add to my site. Can someone please take a look at the following code and see if they can figure it out? Thank you SO much!

    <div id="home-blog" class="posts-list">        
    
    <?php if (have_posts()) :while (have_posts()) : the_post(); ?>
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array( 	'paged' => $paged, 	'orderby' => 'post_date' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post);
    ?> 
    
    <div <?php post_class();?> id="post-<?php the_ID();?>">
    <div class="post-entry">
    <p id="excerpt"><?php $customLength=20; echo get_the_excerpt(); ?></p>
    
    <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
    
    </div><!-- end of .post-entry -->
    </div><!-- end of #post-<?php the_ID(); ?> -->
    <?php endforeach; ?>
    <?php endwhile; ?> 
    
    <?php if (  $wp_query->max_num_pages > 1 ) : ?>
    <div class="navigation"><?php wp_pagenavi(); ?></div><!-- end of .navigation -->
    <?php endif; ?>
    
    <?php else : ?>
    <h1 class="title-404"><?php _e('404 — Fancy meeting you here!', 'responsive'); ?></h1>
    <?php endif; ?>
    </div><!-- end of #home-blog -->
Viewing 4 replies - 1 through 4 (of 4 total)
  • I suggest you replace the use of ‘get_posts()’ with ‘new WP_Query()’ and follow the instructions in the article below to get wp_pagenavi() working: https://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html

    Thread Starter kikimarie123

    (@kikimarie123)

    Thanks for the feedback but that did not work. It actually made all my posts disappear except for the latest.

    OK, please try this:

    <div id="home-blog" class="posts-list">
    
    <?php if (have_posts()) :while (have_posts()) : the_post();
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args = array( 	'paged' => $paged, 	'orderby' => 'post_date' );
       $postslist = new WP_Query( $args );
       if ( $postslist->have_posts() ) :
          while ( $postslist->have_posts() ) :
             $postslist->the_post();
             ?>
    
             <div <?php post_class();?> id="post-<?php the_ID();?>">
                <div class="post-entry">
                   <?php echo '<p>POST NUMBER:' . ++$cnt . '</p>'; ?>
                   <p id="excerpt"><?php $customLength=20; echo get_the_excerpt(); ?></p>
    
                   <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
    
                </div><!-- end of .post-entry -->
             </div><!-- end of #post-<?php the_ID(); ?> -->
          <?php endwhile; ?>
    
          <div class="navigation"><?php wp_pagenavi( array( 'query' => $postslist ) ); ?></div><!-- end of .navigation -->
    
       <?php else : ?>
          <h1 class="title-404"><?php _e('404 — Fancy meeting you here!', 'responsive'); ?></h1>
       <?php endif; ?>
     <?php endwhile; endif; ?>
    </div><!-- end of #home-blog -->
    Thread Starter kikimarie123

    (@kikimarie123)

    That worked!!! Thank you SO SO much. I had honestly given up and just queued 500 posts per page… such a pain. Thanks for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Page Navigation Not Working’ is closed to new replies.