Suporte » Desenvolvendo com WordPress » Paginação em listagem com duas queries

  • Olá pessoal,

    Tenho um template personalizado criado em cima do Twenty Ten e um template de página que filtra os posts da categoria 3.

    No index a paginação funciona normalmente, nesta página, não.

    Alguém pode me ajudar a identificar o que estou fazendo errado?

    <div id="conteudo">
    
    			<div id="esquerda">
    <div id="nav-above" class="navigation">
    		<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
    	</div><!-- #nav-above -->
    
    			<!-- Filtrando os posts -->
    				<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $Blog = new WP_Query('cat=3');
    if ($Blog->have_posts()) { ?>
    <?php while ($Blog->have_posts()) : $Blog->the_post();
    $do_not_duplicate = $post->ID; ?>
    
    <div id="evento-<?php the_ID(); ?>" class="evento" ><h4><span class="data-evento"><?php the_time('d-m-Y') ?> - </span><?php the_title(); ?></h4><br />
    <?php the_thumb(); ?>
    <p class="resumo"><?php the_excerpt(); ?></p>
    </div>
    <?php endwhile;
    }
    
    else {
    
    echo "Nenhum evento programado";
    
    }
    ?>
    
    			</div><!-- Esquerda -->		
    
    			<div id="complementar">
    
    			<h3 style="margin-left:-85px">Próximos eventos</h3>
    <br />
    <?php
    $ArtigosFuturos = new WP_Query('post_status=future&order=ASC&showposts=-1');
    if ($ArtigosFuturos->have_posts()) {
    while ($ArtigosFuturos->have_posts()) : $ArtigosFuturos->the_post();
    $do_not_duplicate = $post->ID; ?>
    <li><h4 class="branco"><span class="data-evento"><?php the_time('d-m-Y') ?> - </span><?php the_title(); ?></h4>
    <?php the_content(); ?>
    <br></li>
    <?php endwhile;
    }
    
    else {
    
    echo "Nenhum evento programado";
    
    }
    ?>
    <p class="recua-topo"></p>
    <?php
    	wp_reset_query();
    	$args = array(
    	'category_name' => eventos,
    	'posts_per_page' => -1,
    
    	'orderby' => title,
    
    	'order' => ASC);
    	query_posts($args); ?>
    <select class="txt" id="idSelect" name="nomeSelect" onchange="window.location.href=this.value">
    <option value=""> Eventos realizados</option>
    <?php while (have_posts()) : the_post(); ?>
    <option value="<?php the_permalink() ?>"><?php the_title(); ?></option>
    <?php endwhile;?>
    </select>
    
    			</div><!-- Complementar -->
    
    			</div><!-- Conteudo -->
Visualizando 2 respostas - 1 até 2 (de um total de 2)
  • A paginação só funciona na query global (do arquivo de contexto) aparentemente, se tiver apenas queries secundárias como neste caso, a paginação não funciona mesmo.

    Se o objetivo é ter uma listagem comum e outra secundária, é mais são manter a query global no contexto que estiver (archive.php, category.php) e usar get_posts() para queries simplificada.

    Listas de posts por categorias funcionam através de category.php, você não precisa filtrar qual categoria quer mostrar, então deixe a query principal normamente (no caso get_template_part(‘loop’, ‘archive’)) e adicione as secundárias, a paginação funcionará para a query principal.

    Criador do tópico jvitorcarvalho

    (@jvitorcarvalho)

    Muito obrigado Diana

    Procurei por referências e encontrei este código, creio que solucionará.

    Paz

    <?php
    // Posts Per Page option
    $ppp = get_option('posts_per_page');
    
    if (!is_paged()) {
    	$custom_offset = 0;
    } else {
    	$custom_offset = $ppp*($paged-1);
    }
    
    // Lets suppose we are querying for posts of a certain author in a particular category
    $args = array(
    'numberposts' => $ppp,
    'offset' => $custom_offset,
    'category' => 3
    );
    
    $posts_data = get_posts( $args );
    
    if ( count( $posts_data ) > 0 ) {
    	echo '<ul>';
    	foreach ( $posts_data as $post ) {
    		echo '<li><a href="'.get_permalink( $post->ID ).'">'.$post->post_title.'</a></li>';
    	}
    	echo '</ul>';
    } else {
    	echo '<p>No articles by this user</p>';
    }
    ?>
Visualizando 2 respostas - 1 até 2 (de um total de 2)
  • O tópico ‘Paginação em listagem com duas queries’ está fechado para novas respostas.