Title: sephers2's Replies | WordPress.org

---

# sephers2

  [  ](https://wordpress.org/support/users/sephers2/)

 *   [Profile](https://wordpress.org/support/users/sephers2/)
 *   [Topics Started](https://wordpress.org/support/users/sephers2/topics/)
 *   [Replies Created](https://wordpress.org/support/users/sephers2/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/sephers2/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/sephers2/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/sephers2/engagements/)
 *   [Favorites](https://wordpress.org/support/users/sephers2/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Themes and Templates](https://wordpress.org/support/forum/themes-and-templates/)
   
   In reply to: [Displaying subcategories on category.php](https://wordpress.org/support/topic/displaying-subcategories-on-categoryphp/)
 *  Thread Starter [sephers2](https://wordpress.org/support/users/sephers2/)
 * (@sephers2)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/displaying-subcategories-on-categoryphp/#post-1945645)
 * No worries I found the answer, instead of using get_the_category, I used php 
   functions to split the url up to see the end bit (the slug of the category) and
   then get the stuff based on that, below is my new code:
 *     ```
       <?php
       get_header();
       get_sidebar();
       ?>
       		<div id="content">
       			<?php
       			$self = $_SERVER['PHP_SELF'];
       			$self = basename($self);
       			$catinfo = get_term_by('slug', $self, 'category');
       			$catslug = $catinfo->slug;
       			$catid = $catinfo->term_id;
       			$catname = $catinfo->name;
       			?>
       				<div id="contentheader"><?php echo $catname ?></div><!--END #contentheader-->
       				<p>
       					<?php
       					if($catslug == 'news'){
           					$myposts = get_posts('numberposts=3&offset=0&'.$catshow);
       						foreach($myposts as $post): ?>
       							<li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
       						<?php endforeach; ?>
       					<?php }else{
       					wp_list_categories('title_li=&hide_empty=0&child_of='.$catid);
       					?>
       					<?php } ?>
   
       				</p>
       <?php get_footer(); ?>
       ```
   

Viewing 1 replies (of 1 total)