Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter superslick

    (@superslick)

    Hi, again, I would like to avoid wp_list_categories.

    This was posted in another forum and it’s exactly what i’m looking for, but doesn’t seem to work on 2.5

    Make it a function (to be included within the ‘function.php’ in your theme folder, for example):

    function number_postpercat ($idcat, $post_status=’publish’) {
    global $wpdb;
    $result=$wpdb->get_col(“SELECT c.post_id FROM {$wpdb->post2cat} c INNER JOIN {$wpdb->posts} p ON c.post_id = p.id WHERE c.category_id = $idcat AND p.post_status=’$post_status'”);
    $number=count($result);
    echo $number;
    }

    Then trigger it including the following in the appropiate place of your template:
    <?php number_postpercat (4); ?>
    …where ‘4’ is the required category id.

    Have a good day,
    hip

Viewing 1 replies (of 1 total)