Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I modified my category.php file to pull posts from all the categories that are posted to a main category parent. It's working perfectly. Now I need to get it so that when you click on the child category permalink, it will take you to that category and list all the posts from that category. That's not working perfectly. When I click on the permalink which is

myDomain.com/?cat=12

I get a blank page. This is my category.php file as it is right now. Well, the relevant stuff, I left out the header and footer

<div id="subpageHolder">

<div id="subPage">



    <div id="menu">
        <img src="<?php bloginfo('stylesheet_directory');?>/images/menu.png" width="137" height="30" alt="Our Menu" />

    <div class="clear"></div>

    <?php
 $allcats = get_categories(array('child_of' => get_query_var('cat'), 'number' => 9999,      'order'=> 'asc')); 
 ?><ul id="slider1" style="width: 166px;"><?php
  foreach ($allcats as $cat) :  
 $args = array(
  'category__in' => array($cat->term_id)
 );

  query_posts($args); 
 if (have_posts()) : 
 ?><li><?php
 echo '<div class="menupageContent">';

    $terms = apply_filters( 'taxonomy-images-get-terms', '' );
    if ( ! empty( $terms ) ) {
    foreach( (array) $terms as $term ) {
            if($term->term_id == $cat->term_id) {
              echo wp_get_attachment_image( $term->image_id, 'menu' );
            }
    }
    } 
 $link = get_category_link( $cat->cat_ID );
 echo '<h3><a href="'. $link . '">'.$cat->name.'</a></h3>';
 echo '<ul>';    
 while (have_posts()) : the_post(); ?>

 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  <?php

  endwhile; 
  echo '</ul></div><!--end menupageContent--></li>'; 

  ?>

  <?php else : ?>
  <?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

<?php the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
echo 'No post published in:'.$cat->name;  
 <?php endif; ?>
 <?php
  endif; 
  wp_reset_query();
  endforeach; 
  ?>
  </ul>

So is it possible to throw in another else loop? when I tried it, it didn't work. I had hoped the archive.php file would take care of it but it didn't. I tried a few loops with no luck. I need some good advice as to how to get this to work. Thanks for your time.

share|improve this question
    
Chances are you need to check your $allcats variable for null. You are probably setting the 'category__in' argument to null, or 0, or something that is not valid when a category does not have child categories. –  Eric Holmes Nov 9 '12 at 14:13
    
I don't think I am. The code is above. I have nothing in there set to null or 0 –  Jamie Nov 9 '12 at 17:51
add comment

1 Answer

up vote 0 down vote accepted

I found a solution by changing my categories.php to category-slug.php and then putting the standard loop back into the the category.php file. All seems good now.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.