Title: Getting Permalink For Sub Category In Loop
Last modified: August 21, 2016

---

# Getting Permalink For Sub Category In Loop

 *  Resolved [Gemfruit](https://wordpress.org/support/users/gemfruit/)
 * (@gemfruit)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/getting-permalink-for-sub-category-in-loop/)
 * I’m looping through all of the sub-categories of a certain parent category, and
   am displaying a bunch of information about those sub-categories. I can get the
   description, name, id, etc, but I can’t seem to pin the permalink.
 * Here’s my code:
 * `<h2 class="title" id="post-<?php $child->cat_ID; ?>"><a href="<?php get_permalink(
   get_page_by_title($child->name)); ?>" rel="bookmark" title="Permanent Link to
   <?php echo($child->name); ?>"><?php echo($child->name); ?></a></h2>`
 * $child is the sub-category, and that code is part of a foreach loop. I’ve tried
   numerous attempts to get the permalink, but I keep getting –
 * site.com/category
 * instead of
 * site.com/category/sub-category
 * Any idea what’s wrong with my code?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Gemfruit](https://wordpress.org/support/users/gemfruit/)
 * (@gemfruit)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/getting-permalink-for-sub-category-in-loop/#post-4162638)
 * I’ve discovered the solution myself, because knowledge is power!
 * Here’s my working code, for anyone interested.
 *     ```
       <?php $descendants = get_categories(array('child_of' => 2));
       		foreach ($descendants as $child) { ?>
   
       			<div id="post-<?php $child->cat_ID; ?>" <?php post_class('full-width-excerpt'); ?>>
       				<a href="<?php echo(get_category_link($child->cat_ID)); ?>" <?php the_post_thumbnail(array(260,200), array("src" => z_taxonomy_image_url($child->term_id), "class" => "alignleft post_thumbnail")); ?> </a>
       				<h2 class="title" id="post-<?php $child->cat_ID; ?>"><a href="<?php echo(get_category_link($child->cat_ID)); ?>" rel="bookmark" title="Permanent Link to <?php echo($child->name); ?>"><?php echo($child->name); ?></a></h2>
   
       				<div class="entry">
       				<?php echo($child->category_description); ?>
       				</div>
       			</div>
       	<?php
       		}
       	?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Getting Permalink For Sub Category In Loop’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [structure](https://wordpress.org/support/topic-tag/structure/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Gemfruit](https://wordpress.org/support/users/gemfruit/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/getting-permalink-for-sub-category-in-loop/#post-4162638)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
