• Resolved hungzai

    (@hungzai)


    I faced a problem which was due to possibly a bug in wordpress which was discussed here http://wordpress.org/support/topic/176526?replies=32

    To cut a long story short, I needed to call a category and the no of posts in it and have the information display on a page. Unfortunately [wp_list_categories or wp_list_cats] produces error messages when dealing with categories that have children.

    Due to my limited knowledge of php, I need a help from fellow coders to produce a query where it can count the no of posts and display it.

    It would probably look something like that but i’m not sure how to finish it off though..

    <?php query_posts(‘cat=ID’); ?>
    <?php while (have_posts()) …integer + 1 etc etc

    All i wanted at the end is for eg, Food 43 where 43 is the no of posts.

    Will any kind soul help me out please?

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

    (@hungzai)

    Solved.

    Here is the solution for those who are interested.

    <?php
    global $post;
    $myposts = get_posts(‘numberposts=1&offset=0&category=ID’);
    foreach($myposts as $post) :
    setup_postdata($post);

    function the_category_count( $cat_id ){
    $o = wp_cache_get( $cat_id, ‘category’ );
    print $o->count;
    }
    ?>

    • (<?php the_category_count(ID); ?>)
    • <?php endforeach; ?>

Viewing 1 replies (of 1 total)

The topic ‘A simple help needed from php coder.’ is closed to new replies.