• Hi,

    I’m looking for a bit of help with displaying categories.

    I want my category.php to do the following:

    1) display the name and description of the current category

    I think I’ve got that with

    <?php
    		printf( __( '%s', 'adventure' ), '<span>' . single_cat_title( '', false ) . '</span>' );
    		?><code>and</code><?php
    		// Display optional category description
    		                    $category_description = category_description();
    		                    if ( ! empty( $category_description ) )
    		                        echo '<div class="archive-meta">' . $category_description . '</div>';
    		                get_template_part( 'loop', 'category' );
    		                ?>

    Next I want to display the name and description of any sub categories within this category and be able to style the output. I’ve tried the following, but it doesn’t work as intended.

    <?php //the loop
    		if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php
    $args = array(
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $categories = get_categories($args);
      foreach($categories as $category) {
      	echo '<div class="category-box col">';
        echo '<h3><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h3> ';
        echo '<p> Description:'. $category->description . '</p>';
        echo '</div>';
         }
    ?>
    
    		<?php endwhile; else : ?>
    	<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>

    Any ideas?

    Thanks

  • The topic ‘How do I use category.php to display a list of categories’ is closed to new replies.