Problems with paging in Wordpress

Asked

Viewed 670 times

1

I’m having a problem showing the pagination on a Wordpress page using WP-Pagenavi.

The post_type "pronamic_event" exists on the seat and behind all the query items.

I was able to identify that the error is in the return of the variable $paged that does not return anything, so he always picks up the Es of the ternary condition, which in this case is 1. How to find out where is the $paged?

Follows the code.

<?php

get_header(); ?>
<div class="agenda-10-wrap">
<div class="top">
    <h3><?php if(function_exists('bcn_display'))  bcn_display() ?></h3>
    <h1><?php single_cat_title(); ?></h1>
</div>
<div class="main">
    <div class="col-01">
        <div class="content">
            <ul>
                <?php
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args = array(
                    'posts_per_page' => '12',
                    'paged' => $paged,
                    'post_type' => 'pronamic_event'
                );
                $loop = new WP_Query( $args );
                //loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post();
                ?>
                <li>
                    <?php
                    if ( has_post_thumbnail() ) {
                        the_post_thumbnail('post-thumbnails');
                    } 
                    ?>
                    <p><?php pronamic_the_start_date('d.m.y');?> - <?php pronamic_the_location();?></p>
                    <h4><?php the_title(); ?></h4>
                    <?php $excerpt = get_the_excerpt();?>
                    <p><?php echo string_limit_words($excerpt,25); ?>...</p>
                    <a href="<?php the_permalink() ?>">Leia mais</a>
                </li>
                <?php endwhile; ?>
            </ul>
        </div>
        <div class="bottom-pager">
            <nav>
                <?php if(function_exists('wp_pagenavi')){
                    wp_pagenavi( array( 'query' => $wp_query ) );
                    wp_reset_postdata();
                } ?>
            </nav>
        </div>
    </div>
    <div class="col-02">
        <?php get_sidebar( 'publicidade-ultimas' ); ?>
    </div>
</div>  

  • I was able to identify that the error is in the return of the $paged variable that does not return anything, so it always picks up the ternary condition Else, which in this case is 1. How to find out where the $paged is???

1 answer

3


If the page you are using this code is used as Static front page you have to check the parameter page also.

if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }

$args = array(
   'posts_per_page' => '12',
   'paged'          => $paged,
   'post_type'      => 'pronamic_event'
);
  • Is there any way given to find this paged variable or page??? The problem is it, it returns nothing.

  • Yes, the way I put it in the code. Check the paged first, then the page. It worked ?

  • So, it didn’t work with either of them, but I did the query directly using Wp_query and then programmed the pager in hand, I was very late with the job. thank you very much for the strength!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.