• Resolved presswolfe

    (@presswolfe)


    Hi,

    I would like to display the number of posts within a specific category on a page.

    What code do I need to add to which file and what line of code should be placed within the HTML of the page that I want the count to appear?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,
    if I understand your question, you can edit a category.php template and add this count wherever you need, using get_the_category function to pull out the category_count value.

    something like this example modified

    <?php
    $category = get_the_category();
    echo $category[0]->category_count;
    ?>

    wrapped in an html tag of your choice.

    Hope it may help you, cheers

    Thread Starter presswolfe

    (@presswolfe)

    @parcodeisuoni

    Thanks for getting back to me about it.

    I am having difficulties using that code to do what I’m trying to accomplish on the site.

    If you have time to look at the site at this URL it may be clearer in context.

    Basically, I want to have the number of job posts show in the main column next to where the red links are for each country — similar to how they appear in the left grey sidebar column. The red links point to the posts in each country’s category.

    Any advice would be helpful. Thanks.

    Ok, so you need to make a category-jobs.php template into your child-theme dir, some infos explained in template hierarchy; then for what you’re doing you can use wp_list_categories function, which is quite versatile, and call it twice each with different args for including/excluding categories from each section (Teaching Jobs in Asia / Other continents).

    When you will be on this specific category template, you will have this list, while in other
    categories the archive.php template of your parent theme will be called instead.

    Give it a try, and of course you need a little css to style it the way you need.

    Thread Starter presswolfe

    (@presswolfe)

    I actually would prefer to have the red links appear arranged exactly as how they are. All I want to do is include the number of job posts appear in brackets next to the red links.

    What you described sounds a bit complicated for my level of “expertise”. Is there a way that I could just add the numbers in brackets beside the red links with some simple steps to follow for how to code it?

    Thread Starter presswolfe

    (@presswolfe)

    Thanks for the help though. I found a way to do it by using two plugins in-tandem with each other: (1) AVH Extended Categories Widgets and (2) Widgetize pages Light

    The first plugin/widget allows more control over what categories are displayed and the “Widgetize pages Light” plugin lets you put the categories on an actual WordPress page.

    It took some tinkering with Firebug to customize the widget’s CSS but it solved the problem without doing any coding with the php files. Wheww.

    Glad you solved this way,
    don’t forget to mark this thread as resolved,

    all the best!

    Thread Starter presswolfe

    (@presswolfe)

    Thanks again! Resolved!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to display post count from a category on a page’ is closed to new replies.