Support » Fixing WordPress » Displaying Information From Sub Category

  • Webpage of interest –

    I have a category of “Articles”, with many sub-categories for each article category. I’m creating a custom page, using a category-articles.php file.

    In this page, I’m trying to display all of the sub-categories, and their information, which includes:

    -an image (I have a plugin to assign categories an image)
    -The name of the category
    -The category description

    I’m very close, but can’t figure out how to reference the information of the child categories, despite the fact that I’m looping through them. Here’s my current code,

    <?php $descendants = get_categories(array('child_of' => 2));
    		foreach ($descendants as $child) { ?>
    			<div id="post-<?php the_ID(); ?>" <?php post_class('full-width-excerpt'); ?>>
    			<h2 class="title" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo($child->cat_name); ?></a></h2>
    			<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(260,200), array("class" => "alignleft post_thumbnail")); } ?>
    			<div class="entry">
    				<?php echo(category_description()) ?>

    echo($child->cat_name) is the only piece of code that’s currently correct, which you can see on the page. Everything else is using the first post in the “Articles” section’s image, description, and links. I see why this is, I simply don’t know the code to reference the sub-category details in each location.

    Any help with this would be greatly appreciated, many thanks for taking the time to check it out.

  • The topic ‘Displaying Information From Sub Category’ is closed to new replies.