WordPress.org

Ready to get started?Download WordPress

Forums

Category Template with Descriptions (6 posts)

  1. mdesilets
    Member
    Posted 6 years ago #

    I would like to be able to list all of the child categories underneath a specific category and display them with a title and description of what that category is. An example of how I would like it to display is here Link (the images are not necessary).

    All of the resources I have found so far... list_categories etc. Put the results into a UL or OL... Can someone point me in the direction of a custom category query or other plugin / resource that might be helpful?

  2. mdesilets
    Member
    Posted 6 years ago #

    The code I was trying to work with...

    <?php wp_list_categories('orderby=id&show_count=10
    &use_desc_for_title=1&child_of=5'); ?> <?php echo category_description(5); ?>

    while this does list the categories... and the second part lists the description... they dont work together... I think I should be using a template but dont know where to start

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    WordPress doesn't have any way to do what you're asking. Look for a plugin to do it or write your own custom code to do it.

  4. mdesilets
    Member
    Posted 6 years ago #

    Otto,

    Thanks for your reply! I've almost solved my problem :) now all I need is some styling and a pesky more link... Is there a cleaner way to do this?

    <?php
    $categories = get_categories("title_li=&orderby=name&hide_empty=0&child_of=5");
    foreach ((array) $categories as $cat) {
    $cat_link = '<h2 class="subhead1"><a href="' . get_category_link($cat->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $cat->cat_name) . '" ' . $rel . '>' . $cat->cat_name.'</a></h2>';
    ?>
    <p><?php echo $cat_link . '' . $cat->category_description; ?></p>
  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    I would have written it like this:

    <?php
    $categories = get_categories("title_li=&orderby=name&hide_empty=0&child_of=5");
    foreach ((array) $categories as $cat) {
    ?>
    <h2 class="subhead1"><a href="<?php echo get_category_link($cat->cat_ID); ?>" title="View all posts in <?php echo $cat->cat_name; ?>"><?echo $cat->cat_name; ?></a></h2>
    <p><?php echo $cat->category_description; ?></p>
    <?php } // end foreach loop ?>
  6. mdesilets
    Member
    Posted 6 years ago #

    that does make more sense... thank you again for your time

Topic Closed

This topic has been closed to new replies.

About this Topic