• CodePoet

    (@design_dolphin)


    What I would like to achieve is this:

    If no children categories exist show post titles in the active category else show children categories.

    This is a excerpt from the category.php template:

    <h1><?php
    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' ';
    }
    ?></h1>
    
    	<h2>Table of contents</h2>
    
    ***(A)***  
    
    <ul><?php echo wp_list_cats('child_of='.$cat);?>
    </ul>
    
    ***(B)*** 
    
    <?php query_posts($query_string .
    '&orderby=title&order=asc&posts_per_page=-1');?>
    	<?php if (have_posts()) : ?>
    		<ul>
    		<?php while (have_posts()) : the_post(); ?>
    			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    		<?php endwhile; ?>
    		</ul>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.

    Where (A) and (B) in the code somehow have to be combined to a statement(?)

    Also how do I get rid of the ‘no categories’ statement that show when there are no categories?

    Has anyone tackled this before, or know how to do this?

    Many thanks ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter CodePoet

    (@design_dolphin)

    With this plugin: https://guff.szub.net/2007/11/30/kinderlose/

    Posts in children categories are not shown.

    Then the following code in category.php only shows the children categories if there are any. If no children categories it shows “no categories”. Add this code before the loop.

    <?php
    $cat = $cat;
    wp_list_categories("orderby=name&show_count=1
    &use_desc_for_title=0&hide_empty=0&child_of=$cat&title_li");
    ?>

    If you leave the parent category empty of posts (which is true in my case.)
    This setup will show the children categories in the current category or if no children categories present the posts in the current category.

    This will print a ‘no categories’ message if the categorie is empty though. Still have to work that part out.

    I’m curious how this turned out for you. I’m trying to suppress the output of “No Categories” and replace it. Any knowledge on this would be much appreciated.

    Thread Starter CodePoet

    (@design_dolphin)

    @prodaea: I just read your message. Honestly I don’t remember. I am not using the function anymore.

    You could possibly override the “no categories” string with an override in functions.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to: If no children categories show post titles in active category’ is closed to new replies.