admin管理员组

文章数量:1126307

I've stumble across an issue on a site Im building. I have tabbed content each holding a category for price ranges in seprate loops. The tabs work great filtering the categories, however some of the posts now have WP page-navi running the pagination, again works fine.

However if I paginate to /page/2 on the first tab the other tabs are then blank/contentless. I can only assume this is a url problem in the pagination so loops are not grabbing the content or I'm not running the loops correctly.

<div id="tabs-1">
     <?php
     $cat_id = get_query_var('cat');
     $limit = get_option('posts_per_page');
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts('showposts=' . $limit = 12 . '&paged=' . $paged .'&cat=' . $cat_id . '');
     $wp_query->is_archive = true; $wp_query->is_home = false;
     ?>
        <?php if (have_posts()) : ?>        
            <?php while (have_posts()) : the_post(); ?> 
                <div class="child-cat-wrap">    
                <div class="child-cat-cont title-slide">      
                 <a href="<?php the_permalink() ?>">

                <div class="title"><span><?php the_title(); ?></span>Read More</div>

                <?php the_post_thumbnail( 'Full Size' ); ?>     
                </a>
                </div>

                <?php echo get_new_excerpt() . '...'; ?>
                <a href="<?php the_permalink(); ?>">more info <span class="meta-nav">&rarr;</span></a>   


                </div>
            <?php endwhile; ?>
            <?php wp_pagenavi(); ?>
        <?php endif ?>
    </div>
    <div id="tabs-2">
     <?php
     $cat_id = get_query_var('cat');
     $limit = get_option('posts_per_page');
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts('showposts=' . $limit = 12 . '&paged=' . $paged .'&cat=-16,-17,' . $cat_id . '');
     $wp_query->is_archive = true; $wp_query->is_home = false;
     ?>
        <?php if (have_posts()) : ?>        
            <?php while (have_posts()) : the_post(); ?> 
                <div class="child-cat-wrap">    
                <div class="child-cat-cont title-slide">      
                 <a href="<?php the_permalink() ?>">

                <div class="title"><span><?php the_title(); ?></span>Read More</div>

                <?php the_post_thumbnail( 'Full Size' ); ?>     
                </a>
                </div>

                <?php echo get_new_excerpt() . '...'; ?>
                <a href="<?php the_permalink(); ?>">more info <span class="meta-nav">&rarr;</span></a> 


                </div>
            <?php endwhile; ?> 
            <?php wp_pagenavi(); ?>  
        <?php endif ?>
    </div>

Any information on this is even possible or a kick in the right direction would be greatly appreciated.

To see the example of the of page I'm testing

I've stumble across an issue on a site Im building. I have tabbed content each holding a category for price ranges in seprate loops. The tabs work great filtering the categories, however some of the posts now have WP page-navi running the pagination, again works fine.

However if I paginate to /page/2 on the first tab the other tabs are then blank/contentless. I can only assume this is a url problem in the pagination so loops are not grabbing the content or I'm not running the loops correctly.

<div id="tabs-1">
     <?php
     $cat_id = get_query_var('cat');
     $limit = get_option('posts_per_page');
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts('showposts=' . $limit = 12 . '&paged=' . $paged .'&cat=' . $cat_id . '');
     $wp_query->is_archive = true; $wp_query->is_home = false;
     ?>
        <?php if (have_posts()) : ?>        
            <?php while (have_posts()) : the_post(); ?> 
                <div class="child-cat-wrap">    
                <div class="child-cat-cont title-slide">      
                 <a href="<?php the_permalink() ?>">

                <div class="title"><span><?php the_title(); ?></span>Read More</div>

                <?php the_post_thumbnail( 'Full Size' ); ?>     
                </a>
                </div>

                <?php echo get_new_excerpt() . '...'; ?>
                <a href="<?php the_permalink(); ?>">more info <span class="meta-nav">&rarr;</span></a>   


                </div>
            <?php endwhile; ?>
            <?php wp_pagenavi(); ?>
        <?php endif ?>
    </div>
    <div id="tabs-2">
     <?php
     $cat_id = get_query_var('cat');
     $limit = get_option('posts_per_page');
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts('showposts=' . $limit = 12 . '&paged=' . $paged .'&cat=-16,-17,' . $cat_id . '');
     $wp_query->is_archive = true; $wp_query->is_home = false;
     ?>
        <?php if (have_posts()) : ?>        
            <?php while (have_posts()) : the_post(); ?> 
                <div class="child-cat-wrap">    
                <div class="child-cat-cont title-slide">      
                 <a href="<?php the_permalink() ?>">

                <div class="title"><span><?php the_title(); ?></span>Read More</div>

                <?php the_post_thumbnail( 'Full Size' ); ?>     
                </a>
                </div>

                <?php echo get_new_excerpt() . '...'; ?>
                <a href="<?php the_permalink(); ?>">more info <span class="meta-nav">&rarr;</span></a> 


                </div>
            <?php endwhile; ?> 
            <?php wp_pagenavi(); ?>  
        <?php endif ?>
    </div>

Any information on this is even possible or a kick in the right direction would be greatly appreciated.

To see the example of the of page I'm testing

Share Improve this question edited Jun 4, 2014 at 4:35 Pieter Goosen 55.4k23 gold badges115 silver badges209 bronze badges asked Oct 24, 2013 at 20:51 Jamie GillJamie Gill 531 silver badge7 bronze badges 5
  • 1 As starting point, you have to read this: wordpress.stackexchange.com/questions/1753/… – brasofilo Commented Oct 24, 2013 at 20:56
  • 1 Thanks brasofilo thats opened my eyes with the loop. Seems i need to be running a wp Query instead of query_posts. Thats will give me a start with new ideas thanks man much appreciated – Jamie Gill Commented Oct 24, 2013 at 21:16
  • Great stuff, managed to split the loops and run them in different variables. Then split the pagination to run in a different format so each tab has a completely seperat pagination in each loop. Thanks again for a kick in the right direction Brasofilo really appreciated its been bending my head for days! – Jamie Gill Commented Oct 25, 2013 at 10:33
  • Bravo! :) Would be nice if you added a brief answer down here, so future readers can know the exact solution. – brasofilo Commented Oct 25, 2013 at 10:35
  • No problem, sorry for the delay I am currently tackling another problem on the site pulls hair out. Thanks again. – Jamie Gill Commented Oct 31, 2013 at 7:43
Add a comment  | 

1 Answer 1

Reset to default 1

Ok solved,

I managed to run a query for each post as a WP_Query instead as Brasofilo pointed out. Then built in the custom pagination via wordpresses help rather than WP_navi as this would not split into sections on one page. As Follows is my new query :-

<?php
$cat_id = get_query_var('cat');
         $limit = get_option('posts_per_page');
         $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
         $the_querynew = new WP_Query('showposts=' . $limit = 45 . '&paged=' . $paged1 .'&cat=' . $cat_id . '');?> 

$paged1 picking up the single pagination and then running the pagination at the bottom of the page as follows :-

<?php  $catstring = get_query_var('cat');
$url = get_category_link( $catstring );
$pag_args1 = array(
'prev_text'    => __('<'),
'next_text'    => __('>'),
'show_all' => true,
'base'         => '' . $url . '?paged1=%#%',                
    'format'  => '?paged1=%#%',
    'current' => $paged1,
    'total'   => $the_querynew->max_num_pages); 
    echo paginate_links( $pag_args1 ); ?>

So simply re running the same query for different posts but running a different variable for the WP_query and $paged1 will give you the correct result.

本文标签: tabsTabbed content with Pagination