Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter hinch

    (@hinch)

    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";
    
    }
    ?>
    Thread Starter hinch

    (@hinch)

    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
     }
    }
    ?>
    Thread Starter hinch

    (@hinch)

    Thanks, I have used is_category to include a different template.

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