[Support request] How to add number of posts in category title

Home Forums Support [Support request] How to add number of posts in category title

Home Forums Support How to add number of posts in category title

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #652908
    Anastasios

    Hi,

    there is a way to add the number of category posts in the category title?

    For example: The category “Summer vacations” to be “12 Posts about summer vacations” where number changes automatically.

    Also in Tags archive.

    Thank you in advance.

    GeneratePress 2.1.3
    GP Premium 1.7.1
    #653140
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You may be able to do something like this: https://wordpress.stackexchange.com/a/20977

    For example:

    add_action( 'generate_after_archive_description', function() {
        if ( is_category() ) {
            $category = get_category();
            $count = $category->category_count;
    
            if ( $count ) {
                echo 'This category has ' . $count . ' posts.';
            }
        }
    } );
    #654284
    Anastasios

    Hi Tom.
    I created a new header element for category archives. Am i able to add this action inside this header or have i to create and add it in a new hook? Will it work if i paste this code in a new hook element and select the display options for inside header?
    Thanx.

    #654308
    David
    Staff
    Customer Support

    Hi there,

    Elements > Header can’t execute PHP. And the code Tom has provided is already applying the Hook, its best added to a Child Function file or using Code snippets plugin. See here:

    https://docs.generatepress.com/article/adding-php/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.