XF 2.2 Thread view count for article threads

M3rein

Member
Hi,

I'd like to add the total view count for an article-type thread somewhere. I don't mind whether it's in the article listing or in the article itself somewhere, as long as it's in at least one or those two places.

Is this doable with just templates, and if so, could someone help me with implementing this?
 
Solution
post_article_macros

this is the bit I added


Code:
<ul class="articlePreview-meta listPlain">
                <li><xf:avatar user="{$thread.User}" size="xxs" defaultname="{$thread.username}"/></li>
                <li class="articlePreview-by">{{ phrase('by_user_x', {'name':$username}) }}</li>
                <xf:comment>PETE added views</xf:comment>
                <li><dl class="pairs pairs--justified structItem-minor">
                <dt>{{ phrase('views') }}</dt>
                <dd>{{ $thread.discussion_type == 'redirect' ? '&ndash;' : ($thread.view_count > $thread.reply_count ? $thread.view_count|number_short : number_short($thread.reply_count+1)) }}</dd>
            </dl></li>
post_article_macros

this is the bit I added


Code:
<ul class="articlePreview-meta listPlain">
                <li><xf:avatar user="{$thread.User}" size="xxs" defaultname="{$thread.username}"/></li>
                <li class="articlePreview-by">{{ phrase('by_user_x', {'name':$username}) }}</li>
                <xf:comment>PETE added views</xf:comment>
                <li><dl class="pairs pairs--justified structItem-minor">
                <dt>{{ phrase('views') }}</dt>
                <dd>{{ $thread.discussion_type == 'redirect' ? '&ndash;' : ($thread.view_count > $thread.reply_count ? $thread.view_count|number_short : number_short($thread.reply_count+1)) }}</dd>
            </dl></li>
 
Solution
post_article_macros

this is the bit I added


Code:
<ul class="articlePreview-meta listPlain">
                <li><xf:avatar user="{$thread.User}" size="xxs" defaultname="{$thread.username}"/></li>
                <li class="articlePreview-by">{{ phrase('by_user_x', {'name':$username}) }}</li>
                <xf:comment>PETE added views</xf:comment>
                <li><dl class="pairs pairs--justified structItem-minor">
                <dt>{{ phrase('views') }}</dt>
                <dd>{{ $thread.discussion_type == 'redirect' ? '&ndash;' : ($thread.view_count > $thread.reply_count ? $thread.view_count|number_short : number_short($thread.reply_count+1)) }}</dd>
            </dl></li>
Works like a charm. Thanks!
 
Last edited:
post_article_macros

this is the bit I added


Code:
<ul class="articlePreview-meta listPlain">
                <li><xf:avatar user="{$thread.User}" size="xxs" defaultname="{$thread.username}"/></li>
                <li class="articlePreview-by">{{ phrase('by_user_x', {'name':$username}) }}</li>
                <xf:comment>PETE added views</xf:comment>
                <li><dl class="pairs pairs--justified structItem-minor">
                <dt>{{ phrase('views') }}</dt>
                <dd>{{ $thread.discussion_type == 'redirect' ? '&ndash;' : ($thread.view_count > $thread.reply_count ? $thread.view_count|number_short : number_short($thread.reply_count+1)) }}</dd>
            </dl></li>
In post_article_macros where exactly should i place the code?
 
In post_article_macros where exactly should i place the code?
Find the first line of his code (ul class =...) in the macro. That's not really part of his code, but show where to actually place it. Then paste the rest of the code under that. At least that's what worked for me. Unfortunately, I am using the 4x4 grid format that Brogan posted in a Resource and the Views: item in the footer doesn't format well in that layout. But I can probably do some tinkering now that I have the basic code.
 
After this:

Code:
<li><xf:avatar user="{$thread.User}" size="xxs" defaultname="{$thread.username}"/></li>
                <li class="articlePreview-by">{{ phrase('by_user_x', {'name':$username}) }}</li>

You add this

Code:
<li><dl class="pairs pairs--justified structItem-minor">
                <dt>{{ phrase('views') }}</dt>
                <dd>{{ $thread.discussion_type == 'redirect' ? '&ndash;' : ($thread.view_count > $thread.reply_count ? $thread.view_count|number_short : number_short($thread.reply_count+1)) }}</dd>
            </dl></li>
 
Back
Top Bottom