XF 2.2 Finding number of views for an article forum

Mendalla

Well-known member
We have our first article forum running, a kind of "feature blog" where a member (who also happens to my co-admin and co-founder of the board) is posting material she originally put out on social media. She would like to know how many views the threads are getting but we are running it with the Preview layout which does not show views. I did some searching and found (and voted up) the suggestion below, but does anyone know a way to do this now short of switching the article forum to the default forum list layout? I am even game to use SQL if needed but I am not sure what tables to use just looking at the database (is the schema published anywhere??).

 
Solution
I just did an edit to post_article_macros template

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>
That's interesting, wonder why no one has answered this... isn't there a way to enable view count so we can see it?

It's an important piece of information I think ?
 
LOL. Forgot I had posted this. Senior moment, I guess. Thanks for the bump. Just spun up another article forum yesterday, in fact. Question still stands, of course.
 
Maybe this could be of some help?
 
Maybe this could be of some help?
It is indeed. Thanks for pointing out that thread. (y)
 
I just did an edit to post_article_macros template

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
I modified that code from @Mr Lucky a little bit for me (default style, XF 2.2.x) and add font awesome und a title

Template:
post_article_macros (use the TMS or made a ow add-on from)

HTML:
        <footer class="articlePreview-footer">
            <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>
                <li><a href="{$link}" class="u-concealed" rel="nofollow"><xf:date time="{$thread.post_date}"/></a></li>
                <li class="u-flexStretch"><a href="{{ link('threads/post', $thread, {'post_id': $post.post_id}) }}"
                    class="u-concealed"
                    data-xf-init="share-tooltip"
                    data-href="{{ link('posts/share', $post) }}"
                    aria-label="{{ phrase('share')|for_attr }}"
                    rel="nofollow">
                    <xf:fa icon="fa-share-alt"/>
                </a></li>
                <xf:comment>START - Otto added views 09/2023</xf:comment>
                <li><dl class="pairs pairs--justified structItem-minor">
                    <dd><i class="fal fa-eye" title="{{ phrase('views') }}: {$thread.view_count|number}"></i> {{ $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>
                <xf:comment>END - Otto added views 09/2023</xf:comment>
                <xf:if is="$thread.reply_count">
                    <li class="articlePreview-replies"><a href="{$linkUnread}"
                        title="{{ phrase('replies:') }} {$thread.reply_count|number}">
                        <xf:fa icon="fa-comment" class="u-spaceAfter" /><span class="articlePreview-repliesLabel">{{ phrase('replies:') }} </span>{$thread.reply_count|number}</a></li>
                </xf:if>

by the way - what I add was this: (I use Font Awesome icon instead of text for views and add a mouse over title like default for replies.)
HTML:
<xf:comment>START - Otto added views 09/2023</xf:comment>
                <li><dl class="pairs pairs--justified structItem-minor">
                    <dd><i class="fal fa-eye" title="{{ phrase('views') }}: {$thread.view_count|number}"></i> {{ $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>
<xf:comment>END - Otto added views 09/2023</xf:comment>

The result:
1695563167484.png
T
 
Top Bottom