• Resolved Graham

    (@grahamuk33)


    I have Category.php showing all posts that relate to each category, but what I would like to include is a link to any Sub-Categories that are also related to that category.

    The code attached shows all Parent Categories, can this be simply edited to show Sub-Categories?

       <div class="category-advert-wrapper">
         <?php
           // display all child categories
           $args = array(
             'orderby' => 'name',
             'hierarchical' => 1,
             'taxonomy' => 'category',
             'hide_empty' => 1,
             'parent' => 0,
             // 'child_of' => 0,
           );
           $categories = get_categories($args);
         ?>
           <?php
             foreach($categories as $category) :
           ?>
         <div class="category-advert">
            <a href="<?php echo get_category_link($category->cat_ID) ?>"
               title="<?php echo esc_attr($category->name) ?>">
               <?php echo z_taxonomy_image($category->cat_ID) ?>
               <div class="category-advert-title">
               <?php echo $category->name; ?>
               </div>
            </a>
         </div>
           <?php
             endforeach;
           ?>
       </div>

    It would really apricated if I can get the code amended for what I require.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Try this for $args:

           $args = array(
             'orderby' => 'name',
             'hierarchical' => 1,
             'taxonomy' => 'category',
             'hide_empty' => 1,
             'child_of' => get_queried_object_id(),
           );
    Thread Starter Graham

    (@grahamuk33)

    Many thanks @bcworkz I have done the amendment to the code and it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding links to sub-categories within a category’ is closed to new replies.