Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Category Template is not working properly WordPress

  • REFUNDED

The category template "category.php" is not working properly.

Basic thing: I have six different product segment and that has been coded using page template.
Under each product page there are products that belongs to specific child category.

Example: Home --> Parent Category --> Child category

There are category duplication among six product page. Suppose, if a page is named "page one" and another page is "page two", so, under "page two", "page one's" categorical product is displayed using custom menu system.

Now, when url is http://somesite.com/product-page/ is working fine but when viewing with http://somesite.com/category/product-page/ the custom menu system is breaking. And that is happening due to malfunctioning of category.php. Pagination on category.php is not working properly, showing 404 error.

ONE THING: I'm conditionally accessing parent category with is_category() function because to show up all the products under that category.

Here is "category.php" code :::


<?php get_header(); ?>
<?php the_breadcrumb(); ?>
<div id="container">
<div id="content-cat" role="main">

<?php
global $query_string;
if (is_category('Consumables')) {
$cat = get_option('id_consum_cat');
query_posts($query_string . "&category_name=" . $cat . "&showposts=10&orderby=title&order=ASC");
}
else {
query_posts($query_string ."&showposts=10&orderby=title&order=ASC");
}
?>

<?php if (!have_posts()) : ?>
<h1 class="entry-title">Will be added soon...</h1>
<?php else : ?>
<h1 class="entry-title"><?php echo single_cat_title("", TRUE); ?></h1>
<?php endif; ?>

<?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
$thumb = get_post_meta($post->ID, '_mcf_block-one', true);
$pattern= "/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i";
preg_match($pattern, $thumb, $thePath);
$theSrc = $thePath[0];
?>
<a href="<?php echo get_image_path($post->ID); ?>" rel="big-image"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb' ); } ?></a>
<!--<img class="hovered" src="<?php bloginfo('template_url'); ?>/images/zoom.png" />-->
</div>
<div class="cat-entry">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="" 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 (function_exists ('wp_pagenavi')) : wp_pagenavi(); else : ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php next_posts_link( __( 'Next <span class="meta-nav">&rarr;</span> ', 'twentyten' ) ); ?></div>
</div>
<?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);

global $menu_class;
$menu_class = "";
if ($back_to_current == "Life Sciences" || $current_category == "Life Sciences") { $menu_class = "lsc"; }
if ($back_to_current == "Histology" || $current_category == "Histology") { $menu_class = "hist"; }
if ($back_to_current == "Forensics" || $current_category == "Forensics") { $menu_class = "foren"; }
if ($back_to_current == "Clinical" || $current_category == "Clinical") { $menu_class = "clinic"; }
if ($back_to_current == "Laboratory" || $current_category == "Laboratory") { $menu_class = "lab"; }
if ($back_to_current == "Consumables" || $current_category == "Consumables") { $menu_class = "con"; }

?>

<?php if ( is_category( array( 'life-sciences','laboratory','consumables','histology','forensics','clinical' ) ) == $current_category) { ?>
<?php echo '<div id="cat-menu"><h3 class="'.$menu_class.'">'.$current_category.'</h3>'; wp_nav_menu( array('container_id' => 'sub-page', 'menu' => $current_category ) ); echo '</div>'; } elseif ( ! have_posts() ) { ?>
<?php echo ''; } else { ?>
<?php echo '<div id="cat-menu"><h3 class="'.$menu_class.'">'.$back_to_current.'</h3>'; wp_nav_menu( array('container_id' => 'sub-page', 'menu' => $back_to_current ) ); echo '</div>'; } ?>

<?php get_footer(); ?>

Answers (1)

2011-07-11

Alex Sancho answers:

If you're using wp-pagenavi with a custom query you need to pass the query as an argument to make it work properly.

There's an example code of how to use it,


function pagination($query = false)
{
if (function_exists('wp_pagenavi'))
{
$args = array('options' => PageNavi_Core::$options->get_defaults());

if ($query)
{
$args['query'] = $query;
}

wp_pagenavi($args);
}
}


Espreson Media comments:

there are other problem on category.php, not only pagination.