Problems with pagination in WordPress

1

I have a problem to make paging appear on a WordPress page using WP-Pagenavi.

The post_type "pronamic_event" exists in the database and brings all the items of the query.

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

Follow 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>  

    

asked by anonymous 16.04.2014 / 04:29

1 answer

2

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

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'
);
    
16.04.2014 / 05:40