XF 2 Total post / thread counts in a category strip

Shamatix

Active member
Hey there,

I am unsure if the following needs development, but is it possible to show the total post and thread count on the forum index in a category strip, next to the catergory title for all the nodes inside of it?

Like how do I get the values etc?

Best regards :)
 
If you have a flat level tree where each forum’s total posts is the sum of all the direct posts inside it + all the post inside any of the sub forum under that forum, then you could just loop through all the nodes who have the same parent ID and count them in a map. In that case, you might be able to do it with a template modification.
 
If you have a flat level tree where each forum’s total posts is the sum of all the direct posts inside it + all the post inside any of the sub forum under that forum, then you could just loop through all the nodes who have the same parent ID and count them in a map. In that case, you might be able to do it with a template modification.
Hello, due to my bad level in english and coding i ca't understand what you mean.
Is there a native variable for the total posts per category ?
 
Maybe this {$extras.message_count|number_short(1)} but how to link it to a category if i want to use it anywhere on the forum ?
 
Edit the template node_list_category
Change Line 6 <a href="{{ link('categories', $node) }}">{$node.title}</a>

To
HTML:
<a href="{{ link('categories', $node) }}">{$node.title}</a> <dl class="pairs pairs--inline">
                                <dt>{{ phrase('threads') }}</dt>
                                <dd>{$extras.discussion_count|number_short(1)}</dd>
                            </dl>
                            <dl class="pairs pairs--inline">
                                <dt>{{ phrase('messages') }}</dt>
                                <dd>{$extras.message_count|number_short(1)}</dd>
                            </dl>
 
Last edited:
Edit the template node_list_category
Change Line 6 <a href="{{ link('categories', $node) }}">{$node.title}</a>

To
HTML:
<a href="{{ link('categories', $node) }}">{$node.title}</a> <dl class="pairs pairs--inline">
                                <dt>{{ phrase('threads') }}</dt>
                                <dd>{$extras.discussion_count|number_short(1)}</dd>
                            </dl>
                            <dl class="pairs pairs--inline">
                                <dt>{{ phrase('messages') }}</dt>
                                <dd>{$extras.message_count|number_short(1)}</dd>
                            </dl>

This is a nice little code but how to style the "threads" and "Posts" text?
 
And is there away to float this right? Where would I put the CSS float code?
Put the css in template extra.less:
CSS:
/* float categories threats and post stats right */
    .pairs.pairs--inline{
    float: right;
}

how to style the "threads" and "Posts" text?
Example to change the color (text green, numbers purple):
CSS:
/* float categories threats and post stats right */
    .pairs.pairs--inline{
    float: right;
        color: purple;
}
.block-header{
    dt{color: green;}
}
 
Hello thank you so much for your reply. That worked but it smooshed the text and numbers a bit.

See attached. :)
 

Attachments

  • Screenshot (170).webp
    Screenshot (170).webp
    1.8 KB · Views: 19
This is a screenshot from my second forum:
Screenshot_2021-05-22 Master Forum.webp
To change the color of the categorie tekst (red in my example) you need to put 1 extra line in the css code:
CSS:
/* float categories threats and post stats right */
    .pairs.pairs--inline{
    float: right;
        color: purple;
}
.block-header{
    color: red;
    dt{color: green;}
}
In my screenshot you can see the 3 colors (red, green and purple) from the code. With that information you can now adjust the colors yourself.
 
Hello Thank you. Yes I got that to work. I was referring to the float right. It squishes the text and numbers a bit. It looks like you're does the same.
 
Hello Thank you. Yes I got that to work. I was referring to the float right. It squishes the text and numbers a bit. It looks like you're does the same.
Maybe it will look better with the padding option:
CSS:
/* float categories threats and post stats right */
    .pairs.pairs--inline{
    float: right;
        color: purple;
}
.block-header{
    color: red;
    dt{color: green;}
    dl{padding: 5px;}
}
This creates a little space in between "posts" and "topics". If desired, you can also change the size of the text via CSS.
 
Hello thank you again! Yes this works for the numbers but it displaces the Category text a bit. Moves it up a few noticeable pxs.

See attached.
 

Attachments

  • Screenshot (172)_LI.webp
    Screenshot (172)_LI.webp
    13.1 KB · Views: 19
Maybe this {$extras.message_count|number_short(1)} but how to link it to a category if i want to use it anywhere on the forum ?

Did you ever work this out? I'm trying to do something similar, but I need to find a way to link the code to the category I want to display elsewhere.
 
Top Bottom