Support » Fixing WordPress » Pagination on front-page.php

  • Resolved phpchick


    I cannot seem to figure out what I am doing wrong.

    I simply want to add pagination to my home-page. The person who built the theme has the wp-paginate plugin installed but I can’t seem to get that to work either so I’ve been trying to handcode the pagination in and have been experiencing difficulty.

    Here is the actual page

    I’m not getting even links at the bottom that say “next” or “Previous”

    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$args = array(
    			'post_type' => 'earnings',  //use to be stock
    			'posts_per_page' => get_field('stocks'), //use to be stocks
    			'paged' => $paged
    		$the_query = new WP_Query( $args );
    		while ( $the_query->have_posts() ) : $the_query->the_post();
    	<?php endwhile; ?>
    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    	<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    	<?php if(function_exists('wp_paginate')) {  //THIS IS ME PLAYING AROUND WITH wp_paginate but not succeeding
    	} ?>
     <?php wp_reset_postdata(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael



    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('&laquo; Older Entries',$the_query->max_num_pages) ?></div>
    	<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;',$the_query->max_num_pages) ?></div>



    So using that snippet causes at least the link “older entries” to show up.

    When you click on it however, it goes to but all the stories are the same as the first.

    In addition, the link on ‘page/2’ is a link to itself, ‘page/2’ if that makes sense.



    there might be something before your code (could be in any template which gets included or called before your code, or from a plugin) which messes with the querystring, so that the ‘paged’ information is lost.

    make sure all queries are closed off properly with wp_reset_query() or wp_reset_postdata().

    for debugging, try to print the paged variable to see if it gets set properly.



    Just want to follow up. I solved the problem and I did it by adding these lines

    global $paged, $wp_query, $wp;
    $args = wp_parse_args($wp->matched_query);
    if ( !empty ( $args['paged'] ) && 0 == $paged ) {
      $wp_query->set('paged', $args['paged']);
      $paged = $args['paged'];

    I added them right before these lines

    $wp_query = new WP_Query( $args );    //these 3 $wp_query use to be "$the_query"   --  when you change these to wp_query, it seems to enable the wp_paginate
    		while ( $wp_query->have_posts() ) : $wp_query->the_post();

    and the reason is this

    “$paged (it doesnt matter if you make it global and access via the variable $paged or you use get_query_var(‘paged’) always resolves to 0.
    The /page/2 matches the correct rewrite rules.

    matched_rule: page/?([0-9]{1,})/?$
    matched_query: index.php?&paged=$matches[1]
    matched_query (evaluated): &paged=2

    but, $paged is 0 no matter what.”

    And I found the above (and the solution), here

    And then, to get wp_paginate working properly (it was showing every post on the same page, while looping the html over and over again),

    I added wp_reset_query immediately following the code for wp-paginate, like so

    <?php if(function_exists('wp_paginate')) {

    Thanks for all the help alchymyth x0x0

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pagination on front-page.php’ is closed to new replies.