Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Can't get the paginate_links nav to update after first click

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #167781
    rpk
    Participant

    I try to get paginate_links working with a custom query in WordPress 3.8.1. The initial paginate_links nav looks correct here

    But if i click page number three the nav doesn’t change. number one stays having the current class without a link, the previous link as prefix is still missing, basically it looks still the same like before the first click

    So basically the paginate_links nav isn’t reflecting the changes after the first click, but each page is displaying the containing news posts correctly. just the nav isn’t working. The php code is the following:

    
    <section class="news-main" role="main">
        <?php
            $args = array(
                'post_type' => 'news',
                'posts_per_page' => '3',
                'paged' => get_query_var( 'paged' )
            );
            $the_query = new WP_Query( $args );
            $temp_query = $wp_query;
            $wp_query = NULL;
            $wp_query = $the_query;
            $total_pages = $wp_query->max_num_pages;
            if ( $total_pages > 1) {
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $current_page = new WP_Query('post_type=news&posts_per_page=1&paged=' . $paged);
                $pagination = array(
                    'base' => '%_%',
                    'format' => '?paged=%#%',
                    'mid-size' => 1,
                    'current' => $current_page,
                    'total' => $total_pages,
                    'prev_next' => True,
                    'prev_text' => __( '<< Previous' ),
                    'next_text' => __( 'Next >>' )
                );
            }
            if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <article class="news-snippet">
                <header class="news-box">
                    <p class="slogan-head fancy"><span class="fancy-hook"><?php the_time( 'j. F Y' ); ?></span></p>
                    <a href="<?php the_permalink(); ?>"><h2 class="logan-state closure"><?php the_title(); ?></h2></a>
                </header>
                <div class="news-wrap">
                    <p class="news-excerpt"><?php echo acf_excerpt( 'news_post', 35, ' <span class="news-more-inbox">[...]</span>' ); ?></p>
                    <p class="news-more"><a href="<?php the_permalink(); ?>">More &rarr;</a></p>
                </div>
            </article>
        <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>
        <?php else: ?>
            <p>DB Error</p>
        <?php endif; ?>
        <div class="">
            <?php echo paginate_links( $pagination ); ?>
        </nav>
        <?php    $wp_query = NULL;
                $wp_query = $temp_query; ?>
    </section>
    

    If anyone might have a clue and suggestion how to fix that issue i would be more than happy. thanks Ralf

    #167782
    rpk
    Participant

    Ok i think i figured things out. The nav is working now, there is only one slight flaw left. The updated codesnippet looks like that:

    
    $args = array(
        'post_type' => 'news',
        'posts_per_page' => '3',
        'paged' => get_query_var( 'paged' )
    );  
    $the_query = new WP_Query( $args );
    $temp_query = $wp_query;
    $wp_query = NULL;
    $wp_query = $the_query;
    $total_pages = $wp_query->max_num_pages;
    if ( $total_pages > 1) {
        $the_paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $pagination = array(
            'base' => @add_query_arg('paged','%#%'),
            'format' => '?paged=%#%',
            'mid-size' => 1,
            'current' => $the_paged,
            'total' => $total_pages,
            'prev_next' => True,
            'prev_text' => __( '<< Previous' ),
            'next_text' => __( 'Next >>' )
        );
    }
    

    the only problem left is that the first page has also the paged snippet as slug. instead of news/ it is also news/?paged=1

    is it possible that the first page has news/ and the rest news/?paged= ? Best regards Ralf

    #167861
    rpk
    Participant

    Ok finally found a working combination for the last problem:

    'base' =&gt; get_pagenum_link(1) . '%_%', 
    'format' =&gt; '?paged=%#%',
    

    Cheers r.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.