• Hi,
    I want to have 2 loops on one site and different pagination I tried to do for several hours also try to use it google but without result. I don’t have any idea how to do it without hack wordpress core anyone can help me?

    My template:

    <?php 
    
    if ( arras_get_option('single_meta_pos') == 'bottom' ) add_filter('arras_postfooter', 'arras_postmeta');
    else add_filter('arras_postheader', 'arras_postmeta');
    
    ?>
    	<?php arras_above_post() ?>
    	<div id="post-<?php the_ID() ?>" <?php arras_single_post_class() ?>>
    		<h2 class="entry-title">
    			<a href=''>Projekty</a>
    		</h2>
    <?php 
    
    $query = array(
    	'category_name' => 'case-study',
    	'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1,
    	'showposts' => 2
    );
    
    query_posts($query);
    
    ?>
    <br />
    <p style='color:#808080'><b>Case study</b></p>
    <table border=0 cellspacing=0 cellpadding=0>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<tr>
    		<td width="158" align="right" class='cv' rowspan='2' style='vertical-align: middle; text-align: center;width158px!important;background-color: #fff;'>
    					<?php $pictures = get_post_meta($post->ID, "pic", true);
    
    					$tmp = explode(",", $pictures);
    					?>
          <img src='/wp-content/themes/arras-theme/library/timthumb.php?src=<?php echo urlencode($tmp[0]); ?>&w=176&zc=0' />
    
    		</td>
    		<td align="left" class='cv' colspan='3'><b><?php the_title(); ?></b><p><?php echo arras_strip_content(get_the_excerpt(), 20); ?></p></td>
    	</tr>
    	<tr>
    		<td width="67%">&nbsp;</td>
    		<td width="33%" align='right' class='details'><a href='<?php the_permalink(); ?>'>&raquo; Więcej</a></td>
    	</tr>
    
    <?php endwhile; endif; ?>
    </table>	
    
    <?php if(function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
    	<div class="navigation clearfix">
    		<div class="floatleft"><?php next_posts_link( __('Older Entries', 'arras') ) ?></div>
    		<div class="floatright"><?php previous_posts_link( __('Newer Entries', 'arras') ) ?></div>
    	</div>
    <?php } ?>
    <?php 
    
    $query = array(
    	'category_name' => 'projekty',
    	'paged' => $paged,
    	'showposts' => 1
    );
    query_posts($query);
    
    ?>
    <br />
    <p style='color:#808080'><b>Projekty</b></p>
    <table border=0 cellspacing=0 cellpadding=0>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<tr>
    		<td width="158" align="right" class='cv' rowspan='2' style='vertical-align: middle; text-align: center;width158px!important;background-color: #fff;'>
    			<?php $pictures = get_post_meta($post->ID, "pictures", true);
          echo $pictures;
          ?></td>
    		<td align="left" class='cv' colspan='3'><b><?php the_title(); ?></b><p><?php echo arras_strip_content(get_the_excerpt(), 20); ?></p></td>
    	</tr>
    	<tr>
    		<td width="67%">&nbsp;</td>
    		<td width="33%" align='right' class='details'><a href='<?php the_permalink(); ?>'>&raquo; Więcej</a></td>
    	</tr>
    
    <?php endwhile; endif; ?>
    </table>	
    
    <?php if(function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
    	<div class="navigation clearfix">
    		<div class="floatleft"><?php next_posts_link( __('Older Entries', 'arras') ) ?></div>
    		<div class="floatright"><?php previous_posts_link( __('Newer Entries', 'arras') ) ?></div>
    	</div>
    <?php } ?>
    
    </div>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sc0rp

    (@sc0rp)

    Thank you for reply, but maybe I was not clear enough to show the problem. The problem isn’t to put 2 loops on the same template, but dedicated pagination for each loop.

    I will try to clean code which I posted:

    <!-- first loop --->
    $query = array(
    	'category_name' => 'case-study',
    	'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1,
    	'showposts' => 2
    );
    
    query_posts($query);
    
    ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!-- do_something-->
    <?php endwhile; endif; ?>
    <!-- end of first loop -->
    
    <!-- pagination for first loop -->
    <div class="navigation clearfix">
    		<div class="floatleft"><?php next_posts_link( __('Older Entries', 'arras') ) ?></div>
    		<div class="floatright"><?php previous_posts_link( __('Newer Entries', 'arras') ) ?></div>
    	</div>
    <!-- end of pagination for first loop -->
    
    <!-- second loop -->
    $query = array(
    	'category_name' => 'projekty',
    	'paged' => $paged,
    	'showposts' => 1
    );
    query_posts($query);
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!-- do something -->
    <?php endwhile; endif; ?>
    <!-- end of second loop -->
    
    <!-- pagination for second loop -->
    <div class="navigation clearfix">
    		<div class="floatleft"><?php next_posts_link( __('Older Entries', 'arras') ) ?></div>
    		<div class="floatright"><?php previous_posts_link( __('Newer Entries', 'arras') ) ?></div>
    	</div>
    <!-- end of pagination for second loop -->

    dedicated pagination for each loop.

    I don’t think you will get pagination to work with two loops.

    I’ve wondered if the plugin http://coffee2code.com/archives/2009/04/18/inject-query-posts-v10-new/ might not be used in a situation like yours.

    Micheal, that’s good thinking on the inject query post, but it breaks pagination. I’ve also tried using some very similar functions to properly paginate multiple loops with the same outcome.

    I also don’t believe that you’ll get pagination working (properly) with two loops but I figured I’d throw this out there one last time to see if perchance anyone has in fact, done so.

    I DO have two queries running side by side on an author.php with pagination.
    The only problem i’ve been unable to solve is forcing the number of results for each query so that each paginated page shows the same number of results regardless of time frame.

    For instance, if one of the queries returns seven posts within a certain timeframe, then the second query will only display the posts within that same timeframe for each paginated page. So in this example an author who has written 9 new posts in cat 1 and all posts in cat 2 are older, the cat 2 posts will only show up on page(s) 2,3 etc.. and vice versa.

    <div id=”magazine_articles”>
    <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    $author = $curauth->user_login; $query= ‘paged=’ . $paged . ‘&author_name=’ . $author . ‘&orderby=date&showposts=9&posts_per_page=-1’;
    $the_query = new WP_Query($query); ?>
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
    <?php if (in_category(‘2’)) continue; ?>
    <– do stuff –>
    <?php endwhile; endif; ?>
    </div>

    <div id=”blog_posts”>
    <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    $author = $curauth->user_login; $other_query= ‘paged=’ . $paged . ‘&author_name=’ . $author . ‘&cat=1&orderby=date&showposts=9&posts_per_page=-1’;
    $the_other_query = new WP_Query($other_query); ?>
    <?php while ($the_other_query->have_posts()) : $the_other_query->the_post(); ?>
    <– do stuff –>
    <?php endwhile;?>
    </div>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘2 loops and different pagination’ is closed to new replies.