Title: hinch's Replies | WordPress.org

---

# hinch

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

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

 Search replies:

## Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

 *   Forum: [Themes and Templates](https://wordpress.org/support/forum/themes-and-templates/)
   
   In reply to: [List sub categories with first 3 posts](https://wordpress.org/support/topic/list-sub-categories-with-first-3-posts/)
 *  Thread Starter [hinch](https://wordpress.org/support/users/hinch/)
 * (@hinch)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/list-sub-categories-with-first-3-posts/#post-802959)
 * Since I can’t edit the post above now (is only one edit allowed?) I have actually
   got code I am happy with – I’d be interested to know your thoughts on it:
 *     ```
       <?php
       $parent = get_query_var('cat');
       $categories = get_categories("orderby=id&show_count=1&hide_empty=0&child_of=$parent");
       foreach ($categories as $cat) {
       echo '<h4><a href="'.$cat->category_nicename.'">'.$cat->cat_name."</a></h4>\n";
   
       $cid = $cat->cat_ID;
   
         echo "<ul>\n";
   
         global $post;
         $myposts = get_posts("numberposts=3&offset=0&category=$cid");
         foreach($myposts as $post) :
   
          echo '<li><a href="'; the_permalink(); echo '">'; the_title(); echo "</a></li>\n";
   
         endforeach;
   
         echo '
          <li><a href="' . get_category_link($cid) . "\">More...</a></li>
         </ul>\n\n";
   
       }
       ?>
       ```
   
 *   Forum: [Themes and Templates](https://wordpress.org/support/forum/themes-and-templates/)
   
   In reply to: [List sub categories with first 3 posts](https://wordpress.org/support/topic/list-sub-categories-with-first-3-posts/)
 *  Thread Starter [hinch](https://wordpress.org/support/users/hinch/)
 * (@hinch)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/list-sub-categories-with-first-3-posts/#post-802945)
 * Sorry I forgot to add what I currently have – It works okay but it seems messy:
 *     ```
       function list_posts() {
        $ch = get_query_var('cat');
        $cat_ids = get_all_category_ids("child_of=$ch");
        foreach ( $cat_ids as $cat_id ) {
        ?>
   
       <h4><?php echo get_cat_name($cat_id); ?></h4>
       <ul>
        <?php
        global $post;
        $myposts = get_posts("numberposts=3&offset=1&category=$cat_id");
        foreach($myposts as $post) :
        ?>
           <li><a href="<?php the_permalink(); ?>"><?php the_title(); echo "- $cat_id"; ?></a></li>
        <?php endforeach; ?>
          <li>More...</li>
        </ul>
        <?php
        }
       }
       ?>
       ```
   
 *   Forum: [Themes and Templates](https://wordpress.org/support/forum/themes-and-templates/)
   
   In reply to: [Category and sub-category templates](https://wordpress.org/support/topic/category-and-sub-category-templates/)
 *  Thread Starter [hinch](https://wordpress.org/support/users/hinch/)
 * (@hinch)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/category-and-sub-category-templates/#post-802505)
 * Thanks, I have used is_category to include a different template.

Viewing 3 replies - 1 through 3 (of 3 total)