WordPress.org

Ready to get started?Download WordPress

Forums

Output Number Of Posts In Category (4 posts)

  1. mikedistras
    Member
    Posted 3 years ago #

    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:

    <?php
    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>
    
    </div><!-- .post -->
    
    <?php endwhile ?>
  2. Curtiss Grymala
    Member
    Posted 3 years ago #

    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).

  3. mikedistras
    Member
    Posted 3 years ago #

    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

  4. mikedistras
    Member
    Posted 3 years ago #

    Any luck anybody?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.