Support » Fixing WordPress » Output Number Of Posts In Category

  • Ok, so I know the subject of the title is pretty easy to output with wp_list_categories, but im trying to output it a little differently.

    I would like to display the count for a category + the name of the post title it is currently within.

    eg, there is a post and a category called ‘Awesome Stuff’
    And there is a sub-category called Photos with the Slug of ‘photos-awesome-stuff’

    So the code would need to display something along the lines of:
    <?php wp-list-categories(‘category=photos-‘.the_title.; ?>

    Hope the above makes a little sense. Ive pasted below what is currently in use and not working:

    query_posts( 'cat=45&posts_per_page=4' );
    while ( have_posts() ) : the_post()
    <div id="post-<?php the_ID() ?>" class="post model_grid">							
    <a href="<?php the_permalink() ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail(  ); } ?></a>
    <div class="model_name">
    <?php the_title(); ?><br />
    Photos: <?php echo wt_get_category_count('photos-'.the_title('','',false).); ?>
    </div><!-- .post -->
    <?php endwhile ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try using the get_terms() function to retrieve an array of category objects. Then, you should be able to us the slug property of the returned objects to add the appropriate info, and you might be able to use the count property to output the post count (not sure if get_terms() retrieves the count info or not, but I know that get_category() does).

    Any ideas what I would actually need to write in there?

    Ill need to add this in twice within the same loop.
    Photos: <?php DISPLAY ‘PHOTOS-{POST-TITLE}’ ?>
    Videos: <?php DISPLAY ‘VIDEOS-{POST-TITLE}’ ?>

    Ps. I knnow the above obviously wont work, but should give a clear idea what im trying to achieve

    Any luck anybody?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Output Number Of Posts In Category’ is closed to new replies.