WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Code for pagination query_post not work (10 posts)

  1. micalopes
    Member
    Posted 4 years ago #

    Good morning! (Sorry my bad English, I´m a brazilian girl :) )

    I'm with that problem in pagination when using query_post.
    've Tried countless codes, including:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    
    <?php query_posts('cat=5&showposts=5&paged=$paged'); ?>
    
    <?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>

    Did not work ...
    The only difference, I'm using query_post like this:
    <?php if (is_page('ultimas-noticias')) {query_posts('category_name=Notícias');}?>

    Can anyone give me a help?
    The code of my index.php is:

    <?php get_header(); ?>
    
    <?php if (is_front_page()){include ('sidebar.php'); }
    	if (is_page('nossa-historia')) {include ('sidebar.php'); }
    	if (is_page('nosso-estatuto')) {include ('sidebar.php'); }
    	if (is_home()) {include ('sidebar.php'); }
    	if (is_home()) {query_posts('cat=-3, -6, -7, -8, -9'); }
    	if (is_page('membros')) {include ('sidebar3.php'); }
    	if (is_page('membros-do-staff')) {include ('sidebar3.php'); }
    	if (is_page('membros-oficiais')) {include ('sidebar3.php'); }
    	if (is_page('membros-em-reserva')) {include ('sidebar3.php'); }
    	if (is_page('novos-membros')) {include ('sidebar3.php'); }
    	if (is_page('membros-em-aprovacao')) {include ('sidebar3.php'); }
    	if (is_page('eventos')) {include ('sidebar4.php'); }
    	if (is_page('standards')) {include ('sidebar5.php'); }
    	if (is_page('participe')) {include ('sidebar6.php'); }
    	if (is_page('contato')) {include ('sidebar7.php'); }
    ?>
    
    		<!-- Content -->
    
    		<div id="content">
    
                <?php if (is_page('ultimas-noticias')) {query_posts('category_name=Notícias');}?>
                <?php if (is_page('membros-do-staff')) {query_posts('category_name=Membros do Staff&order=ASC') ;}?>
    			<?php if (is_page('membros-oficiais')) {query_posts('category_name=Membros Oficiais&order=ASC');}?>
                <?php if (is_page('membros-em-reserva')) {query_posts('category_name=Membros em Reserva&order=ASC');}?>
                <?php if (is_page('novos-membros')) {query_posts('category_name=Novos Membros&order=ASC');}?>
                <?php if (is_page('membros-em-aprovacao')) {query_posts('category_name=Membros em Aprovaçao&order=ASC');}?>
    <?php
    global $more;    // Declare global $more (before the loop).
    $more = 0;       // Set (inside the loop) to display all content, including text below more.
    the_content();
    ?>
    
    			<?php if (have_posts()) : ?>
    			<?php while (have_posts()) : the_post(); ?>
    
    			<!-- Post -->
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    				<div class="post-title">
    
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    					<div class="post-title-info">
    
                        Por: <?php the_author() ?> em  <?php the_time('d/m/Y') ?><br />
    
                        </div>
    
                        <div class="clear"></div>
    
    				</div>
    
    				<div class="post-entry">
    
    					<?php the_content('Leia mais...'); ?>
    
    				</div>
    
    				<div class="post-info">
    
    				</div>
    
    			</div>
    
    			<!-- /Post -->
    
    			<?php endwhile; ?>
    
    			<!-- Navigation -->
    
    			<div class="navigation">
    
    				<div class="navigation-previous"><?php next_posts_link('&laquo; Anterior') ?></div>
    
    				<div class="navigation-next"><?php previous_posts_link('Pr&oacute;xima &raquo;') ?></div>
    
    			</div>
    
    			<!-- /Navigation -->
    
    			<?php else : ?>
    
    			<!-- Post -->
    
    			<div class="post">
    
    				<div class="post-title">
    
    					<h2>Not Found</h2>
    
    				</div>
    
    				<div class="post-entry">
    
    					<p>Sorry, but you are looking for something that isn't here.</p>
    
    				</div>
    
    			</div>
    
    			<!-- /Post -->
    
    			<?php endif; ?>
    
    			<div class="clear"></div>
    
    		</div>
    
    		<!-- /Content -->
    
    <?php include (TEMPLATEPATH . '/sidebar-right.php'); ?>
    
    <?php get_footer(); ?>

    Thanks!!!!!!

  2. kz
    Member
    Posted 4 years ago #

    Use
    <?php query_posts('cat=5&showposts=5&paged=' . $paged); ?>
    or
    <?php query_posts("cat=5&showposts=5&paged=$paged"); ?>

  3. micalopes
    Member
    Posted 4 years ago #

    Not work :(

    <?php get_header(); ?>
    
    <?php if (is_front_page()){include ('sidebar.php'); }
    	if (is_page('nossa-historia')) {include ('sidebar.php'); }
    	if (is_page('nosso-estatuto')) {include ('sidebar.php'); }
    	if (is_home()) {include ('sidebar.php'); }
    	if (is_home()) {query_posts('cat=-3, -6, -7, -8, -9'); }
    	if (is_page('membros')) {include ('sidebar3.php'); }
    	if (is_page('membros-do-staff')) {include ('sidebar3.php'); }
    	if (is_page('membros-oficiais')) {include ('sidebar3.php'); }
    	if (is_page('membros-em-reserva')) {include ('sidebar3.php'); }
    	if (is_page('novos-membros')) {include ('sidebar3.php'); }
    	if (is_page('membros-em-aprovacao')) {include ('sidebar3.php'); }
    	if (is_page('eventos')) {include ('sidebar4.php'); }
    	if (is_page('standards')) {include ('sidebar5.php'); }
    	if (is_page('participe')) {include ('sidebar6.php'); }
    	if (is_page('contato')) {include ('sidebar7.php'); }
    ?>
    
    		<!-- Content -->
    
    		<div id="content">
                <?php if (is_page('ultimas-noticias')) {query_posts('category_name=Notícias');}?>
                <?php if (is_page('membros-do-staff')) {query_posts('category_name=Membros do Staff&order=ASC') ;}?>
    			<?php if (is_page('membros-oficiais')) {query_posts('category_name=Membros Oficiais&order=ASC');}?>
                <?php if (is_page('membros-em-reserva')) {query_posts('category_name=Membros em Reserva&order=ASC');}?>
                <?php if (is_page('novos-membros')) {query_posts('category_name=Novos Membros&order=ASC');}?>
                <?php if (is_page('membros-em-aprovacao')) {query_posts('category_name=Membros em Aprovaçao&order=ASC');}?>
    <?php
    global $more;
    $more = 0;
    the_content();
    ?>
    
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    
    <?php query_posts('cat=6&showposts=4&paged=' . $paged); ?>
    
    <?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>
    			<!-- Post -->
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    				<div class="post-title">
    
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    					<div class="post-title-info">
    
                        Por: <?php the_author() ?> em  <?php the_time('d/m/Y') ?><br />
    
                        </div>
    
                        <div class="clear"></div>
    
    				</div>
    
    				<div class="post-entry">
    
    					<?php the_content('Leia mais...'); ?>
    
    				</div>
    
    				<div class="post-info">
    
    				</div>
    
    			</div>
    
    			<!-- /Post -->
    
    			<?php endwhile; ?>
    
    			<!-- Navigation -->
    
    			<div class="navigation">
    
    				<div class="navigation-previous"><?php next_posts_link('&laquo; Anterior') ?></div>
    
    				<div class="navigation-next"><?php previous_posts_link('Pr&oacute;xima &raquo;') ?></div>
    
    			</div>
    
    			<!-- /Navigation -->
    
    			<?php else : ?>
    
    			<!-- Post -->
    
    			<div class="post">
    
    				<div class="post-title">
    
    					<h2>Not Found</h2>
    
    				</div>
    
    				<div class="post-entry">
    
    					<p>Sorry, but you are looking for something that isn't here.</p>
    
    				</div>
    
    			</div>
    
    			<!-- /Post -->
    
    			<?php endif; ?>
    
    			<div class="clear"></div>
    
    		</div>
    
    		<!-- /Content -->
    
    <?php include (TEMPLATEPATH . '/sidebar-right.php'); ?>
    
    <?php get_footer(); ?>
  4. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    try and add the '&paged=' .$paged' bit to each query_posts in your conditional list:

    <div id="content">
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
               <?php if (is_page('ultimas-noticias')) {query_posts('category_name=Notícias&paged=' . $paged);}?>
                <?php if (is_page('membros-do-staff')) {query_posts('category_name=Membros do Staff&order=ASC&paged=' . $paged) ;}?>
    			<?php if (is_page('membros-oficiais')) {query_posts('category_name=Membros Oficiais&order=ASC&paged=' . $paged);}?>
                <?php if (is_page('membros-em-reserva')) {query_posts('category_name=Membros em Reserva&order=ASC&paged=' . $paged);}?>
                <?php if (is_page('novos-membros')) {query_posts('category_name=Novos Membros&order=ASC&paged=' . $paged);}?>
                <?php if (is_page('membros-em-aprovacao')) {query_posts('category_name=Membros em Aprovaçao&order=ASC&paged=' . $paged);}?>
    <?php
    global $more;    // Declare global $more (before the loop).
    $more = 0;       // Set (inside the loop) to display all content, including text below more.
    ?>
    
    	<?php if (have_posts()) : ?>

    hope that helps ;-)

  5. micalopes
    Member
    Posted 4 years ago #

    :´( not work...

    <?php get_header(); ?>
    
    <?php if (is_front_page()){include ('sidebar.php'); }
    	if (is_page('nossa-historia')) {include ('sidebar.php'); }
    	if (is_page('nosso-estatuto')) {include ('sidebar.php'); }
    	if (is_home()) {include ('sidebar.php'); }
    	if (is_home()) {query_posts('cat=-3, -6, -7, -8, -9'); }
    	if (is_page('membros')) {include ('sidebar3.php'); }
    	if (is_page('membros-do-staff')) {include ('sidebar3.php'); }
    	if (is_page('membros-oficiais')) {include ('sidebar3.php'); }
    	if (is_page('membros-em-reserva')) {include ('sidebar3.php'); }
    	if (is_page('novos-membros')) {include ('sidebar3.php'); }
    	if (is_page('membros-em-aprovacao')) {include ('sidebar3.php'); }
    	if (is_page('eventos')) {include ('sidebar4.php'); }
    	if (is_page('standards')) {include ('sidebar5.php'); }
    	if (is_page('participe')) {include ('sidebar6.php'); }
    	if (is_page('contato')) {include ('sidebar7.php'); }
    ?>
    
    		<!-- Content -->
    
    		<div id="content">
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
               <?php if (is_page('ultimas-noticias')) {query_posts('category_name=Notícias&paged=' . $paged);}?>
                <?php if (is_page('membros-do-staff')) {query_posts('category_name=Membros do Staff&order=ASC&paged=' . $paged) ;}?>
    			<?php if (is_page('membros-oficiais')) {query_posts('category_name=Membros Oficiais&order=ASC&paged=' . $paged);}?>
                <?php if (is_page('membros-em-reserva')) {query_posts('category_name=Membros em Reserva&order=ASC&paged=' . $paged);}?>
                <?php if (is_page('novos-membros')) {query_posts('category_name=Novos Membros&order=ASC&paged=' . $paged);}?>
                <?php if (is_page('membros-em-aprovacao')) {query_posts('category_name=Membros em Aprovaçao&order=ASC&paged=' . $paged);}?>
    <?php
    global $more;
    $more = 0;
    ?>
    
    	<?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>
    			<!-- Post -->
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    				<div class="post-title">
    
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    					<div class="post-title-info">
    
                        Por: <?php the_author() ?> em  <?php the_time('d/m/Y') ?><br />
    
                        </div>
    
                        <div class="clear"></div>
    
    				</div>
    
    				<div class="post-entry">
    
    					<?php the_content('Leia mais...'); ?>
    
    				</div>
    
    				<div class="post-info">
    
    				</div>
    
    			</div>
    
    			<!-- /Post -->
    
    			<?php endwhile; ?>
    
    			<!-- Navigation -->
    
    			<div class="navigation">
    
    				<div class="navigation-previous"><?php next_posts_link('&laquo; Anterior') ?></div>
    
    				<div class="navigation-next"><?php previous_posts_link('Pr&oacute;xima &raquo;') ?></div>
    
    			</div>
    
    			<!-- /Navigation -->
    
    			<?php else : ?>
    
    			<!-- Post -->
    
    			<div class="post">
    
    				<div class="post-title">
    
    					<h2>Not Found</h2>
    
    				</div>
    
    				<div class="post-entry">
    
    					<p>Sorry, but you are looking for something that isn't here.</p>
    
    				</div>
    
    			</div>
    
    			<!-- /Post -->
    
    			<?php endif; ?>
    
    			<div class="clear"></div>
    
    		</div>
    
    		<!-- /Content -->
    
    <?php include (TEMPLATEPATH . '/sidebar-right.php'); ?>
    
    <?php get_footer(); ?>

    :( :( :(

  6. kz
    Member
    Posted 4 years ago #

    Is there other loop with query_posts in sidebarx.php?
    You must write wp_reset_query() to close query_post().

  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    Get rid of showposts and replace it with posts_per_page, in your query_posts line.

  8. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    another thought: what if all the ifs are not true, would you need another 'else' query?

  9. vtxyzzy
    Member
    Posted 4 years ago #

    You have another query_posts near the top:

    if (is_home()) {query_posts('cat=-3, -6, -7, -8, -9'); }

    Is that the one not working? Maybe you need to move it down after you set $paged and add the paged parameter to it.

  10. micalopes
    Member
    Posted 4 years ago #

    Thanks!!!!!!! vtxyzzy!!!!!

    Now it´s work!!!!!

    Thanks!!!!! :) :) :)

Topic Closed

This topic has been closed to new replies.

About this Topic