• I’m hoping someone can help me sort out a navigation issue I’m having with my website at SevenSharks.com

    When I first designed my site, It had a custom static front page that was blank like a gateway page. I recently deactivated that page, and made the blog page the static front page. After making the change, my pagination stopped working correctly.

    Clicking “Older” now only loads the same 8 posts (the 8 most recent posts) instead of cycling backwards through older posts.

    Its really driving me crazy.

    Here is the only relevant code as far as I know:

    <?php
        /**
         * For get looping of blog.
         */
        $paged    = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args     = array(
                'orderby' => 'date',
                'order' => 'DESC',
                'paged' => $paged,
        );
        $temp     = $wp_query;  // assign orginal query to temp variable for later use
        $wp_query = null;
        $wp_query = new WP_Query($args);
    ?>
    
    	 <?php get_template_part('loop'); ?>
    
    <?php $wp_query = $temp; wp_reset_postdata(); ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • the meta title in the header thinks it is ‘page 2’, so your ‘older’ link seems to be ok.

    is the slider query properly reset?

    what is the value of $paged on ‘page 2’ when you print it just before your query?

    Can you provide the full page code.
    Paste you code in patepin
    and post the link here.
    So that we can examine the code

    Thread Starter .watts.

    (@watts-1)

    alchymyth, thanks so much for your reply and attempt to help. I was worried I’d get lost in the mix.

    I know the basics but I’m still new to PHP, as such, my noob-like ignorance means I don’t understand what you’re asking. I appreciate your patience!

    to start with, please follow the suggestion by @zebrawebdesigns
    and provide the full code (how-to: https://codex.www.ads-software.com/Forum_Welcome#Posting_Code )

    generally, custom queries like something using WP_Query() need to be reset after their loop; for instance with: wp_reset_postdata() or wp_reset_query()

    my feeling is that your slider does not do this.

    to check that the $paged variable is set properly for your loop, add a test print-out for instance directly after this line:

    $paged    = (get_query_var('paged')) ? get_query_var('paged') : 1;

    example:

    echo $paged;

    Thread Starter .watts.

    (@watts-1)

    Here is the code for the Blog Page:
    https://pastebin.com/ghgY0egK

    Here is the code for the ‘loop’ in the Blog Page:
    https://pastebin.com/aWF91zM1

    Should I include code from the other PHP template pages?

    @.watts. I have used the code you provided and tested in my local. There is no problem in getting the pagination and working without problem.
    Except that here I dont have wp_content_slider() function.

    So I suggest you to Check by commenting the wp_content_slider function
    <?php if(function_exists('wp_content_slider')) { wp_content_slider(); } ?>

    If you get it work then there is problem with content slider.
    Load the content slider before the you start the query for posts.
    and put the wp_reset_query(); before starting the query.
    I give an example in the pastebin
    https://pastebin.com/SS6KGcyM

    Please take the backup of the file before proceeding.

    Thread Starter .watts.

    (@watts-1)

    Found the solution.

    In this portion:

    $paged = (get_query_var(‘paged‘)) ? get_query_var(‘paged‘) : 1;

    should have been:

    $paged = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1;

    Its always the small thing that cripples you. Thanks for your help anyway guys!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Next Posts button just repeats the latest 8 posts’ is closed to new replies.