get post count for a specific category

  • Unknown's avatar

    Hello, I have a site with a single page, on which I placed a frozen block at the top in which I manually write all my categories. I would like to be able to add next to each category the number of articles it contains. Exactly like the “list category” widget does but I don’t want to use this widget because I want 1) to display the categories in rows and not in columns and 2) that the category links are internal links to the page and do not return to the category page. Is there a way to call a function providing the ID of a category that would return the number of items in that category? I wouldn’t be worried about writing php, but it seems necessary to have a paid account to be able to create functions or use php: is that right?

    The blog I need help with is: (visible only to logged in users)

  • Hello there,

    Many thanks for reaching out.

    In order to dynamically get anchor links to update to show the number of posts, you would need a PHP script, and developer assistance.

    However, there is a clever way to do create this behaviour with the use of plugins.

    The first step, would be to add a category list onto the template.

    We can help you alter the look of that list into rows with CSS. Finally, with the use of a redirect plugin: (such as those seen here: https://wordpress.org/plugins/search/redirect%20/) you could redirect category pages, to the anchor link on the page. So when any of these are clicked they would go back to the desired place, but they would showing the number of posts on the front end.

    In order to run both custom CSS and a redirect plugin, a business plan would need to be in use on the site:

    I notice you’re listing a lot of titles on the website – I’m really curious, what’s the site about and do you have long term plans for the site?

    Speak soon!

  • Unknown's avatar

    Thank you for your reply. This page is intended to list the films currently stored in the servers of the cinema for which I work, in order to quickly view all the films to decide more easily which ones to delete (we are not a cinema library and the storage space is necessarily limited) and which ones to keep for possible school sessions. It is therefore a document that is not intended to be public but shared between collaborators (so the site is not indexed). But not having an internal web server, I thought the easiest way would be to use WordPress. For now, there are no plans to invest in a business plan for this tool. But maybe in the long term. For now, it’s easy to get the information in the back office. Later, I think we will install WordPress on a mutalized server or I will start creating a small web server on our internal network and install wordpress. In both case I could then create the function I need (I already created functions a long time ago for another WordPress site). It’s frustrating not being able to get this feature with the free plan. Cordially.

  • Thank you for sharing all that information. I understand what you’re trying to do, and as @aleone89 said, it’s not possible to do it with the Free plan as it has a different configuration and runs on a different infrastructure from the Business plan.

  • The topic ‘get post count for a specific category’ is closed to new replies.