Why the pagination not working in category.php for this two conditional statement.
<?php get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php if ( is_category('general-lab') ) : ?>
<?php //FETCHING ONLY GENERAL LAB CATEGORY
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query("posts_per_page=10&category_name=life-sciences&paged=".$paged); ?>
<h1 class="entry-title"><?php echo single_cat_title("", TRUE); ?></h1>
<?php $count=0; while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if($count % 2 == 0) echo '<div class="left">'; else echo '<div class="right">'; ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="cat-thumb"><?php echo get_post_meta($post->ID, '_mcf_block-one', true); ?></div>
<div class="cat-entry">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
<?php if($count % 2 != 0) echo '<div class="clear"></div>';?>
<?php $count++; endwhile; ?>
<?php if ( $the_query->max_num_pages > 1 ) : ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_posts_link( __( '<span class="meta-nav">←</span> Previous', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php next_posts_link( __( 'Next <span class="meta-nav">→</span> ', 'twentyten' ) ); ?></div>
</div><!-- #nav-below -->
<?php endif; ?>
<?php else : ?>
<h1 class="entry-title"><?php echo single_cat_title("", TRUE); ?></h1>
<?php $count=0; while (have_posts()) : the_post(); ?>
<?php if($count % 2 == 0) echo '<div class="left">'; else echo '<div class="right">'; ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="cat-thumb"><?php echo get_post_meta($post->ID, '_mcf_block-one', true); ?></div>
<div class="cat-entry">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
<?php if($count % 2 != 0) echo '<div class="clear"></div>';?>
<?php $count++; endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_posts_link( __( '<span class="meta-nav">←</span> Previous', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php next_posts_link( __( 'Next <span class="meta-nav">→</span> ', 'twentyten' ) ); ?></div>
</div><!-- #nav-below -->
<?php endif; ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #container -->
<?php $current_category = single_cat_title("", FALSE);
$parent_cat = get_the_category();
$back_to_current = get_cat_name($parent_cat[0]->category_parent);
if ( is_category( array( 'life-sciences','consumables','histology','forensics','pharmaceutical' ) ) == $current_category) { ?>
<?php echo '<div id="cat-menu"><h3>'.$back_to_current.'</h3>'; wp_nav_menu( array('container_id' => 'sub-page', 'menu' => $current_category ) ); echo '</div>'; } elseif ( is_category('general-lab')) { ?>
<?php echo '<div id="cat-menu"><h3>'.$current_category.'</h3>'; wp_nav_menu( array('container_id' => 'sub-page', 'menu' => $back_to_current ) ); echo '</div>'; } else { ?>
<?php echo '<div id="cat-menu"><h3>'.$back_to_current.'</h3>'; wp_nav_menu( array('container_id' => 'sub-page', 'menu' => $back_to_current ) ); echo '</div>'; } ?>
<?php get_footer(); ?>
Pippin Williamson answers:
Try changing your first query to this:
$global $query_string;
WP_Query($query_string . "&posts_per_page=10&category_name=life-sciences&paged=".$paged);
Espreson Media comments:
Sorry!
Not working..
Pippin Williamson comments:
Ok, try replacing
$the_query = new WP_Query("posts_per_page=10&category_name=life-sciences&paged=".$paged);
with:
$global $query_string;
query_posts($query_string . "&posts_per_page=10&category_name=life-sciences&paged=".$paged);
and then replace
<?php $count=0; while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
with
<?php $count=0; while ( have_posts() ) : the_post(); ?>
Espreson Media comments:
Sorry!
Not working..
David Navarrete answers:
you could will try with this
global $wp_query;
and use query_posts instead of WP_Query
Espreson Media comments:
"Sorry" this thing is not working..
Breaking the code when next page browsed...
There are two different category "Life Sciences" and "General Lab" and there are sub-categorical product on "Life Sciences".
Now in "General Lab" has all the sub-category and products which "Life sciences" have. Same product.
Luthfi Bintoro answers:
try this :
change the code :
$the_query = new WP_Query("posts_per_page=10&category_name=life-sciences&paged=".$paged); ?>
with :
query_posts("posts_per_page=10&category_name=life-sciences&paged=".$paged);
global $wp_query;
?>
and then change :
<?php if ( $the_query->max_num_pages > 1 ) : ?>
with
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
hope this help
Denzel Chia answers:
Hi,
With reference to WordPress Template hierarchy. http://codex.wordpress.org/Template_Hierarchy
Why don't you try using different category templates.
category-{slug}.php - If the category's slug were general-lab, WordPress would look for category-general-lab.php
Use a normal WordPress loop in the template and your pagination issues will be solved.
Use category.php for your other categories and use category-{slug}.php for all special categories that you want to have different styles or codes or highlights.
Thanks.
Denzel