Articles counter

Counts posts in a certain forum and displays the count in viewtopic

This snippet will show a count of the users posts or 'articles' from a certain forum, underneath their profile information / avatar in a topic. To keep things as simple as possible the forum id is hard coded into viewtopic, so if you change the forum id you'll have to manually update viewtopic.php as well.

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
        //
        $postrow = array( 
#
#-----[ BEFORE ADD ]------------------------------------------
#
        $article_forum_id = '2'; // Remember to change this to the id of the forum you are using

        $sql = 'SELECT COUNT(*) AS num_articles
            FROM ' . POSTS_TABLE . '
            WHERE forum_id = ' . $article_forum_id . '
                AND poster_id = ' . $poster_id;
        $result = $db->sql_query($sql);
        $total_articles = (int) $db->sql_fetchfield('num_articles');
        $db->sql_freeresult($result);
#
#-----[ OPEN ]------------------------------------------
#
language/en/viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
       'ATTACHMENT'                  => 'Attachment',
#
#-----[ BEFORE ADD ]------------------------------------------
#

Change 'Articles' to any other word if you don't want to use that

       'ARTICLES'                    => 'Articles',
#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/template/viewtopic_body.html
#
#-----[ FIND ]------------------------------------------
#
          <!-- IF postrow.POSTER_FROM --><dd><strong>{L_LOCATION}:</strong> {postrow.POSTER_FROM}</dd><!-- ENDIF -->
#
#-----[ AFTER ADD ]------------------------------------------
#
          <!-- IF postrow.POSTER_ARTICLES > 0 --><dd><strong>{L_ARTICLES}:</strong> {postrow.POSTER_ARTICLES}</dd><!-- ENDIF -->

The above template code hill hide the article count from users with no articles in that forum. If you'd rather that a 0 count was shown, use this code instead

          <!-- IF postrow.POSTER_ARTICLES --><dd><strong>{L_ARTICLES}:</strong> {postrow.POSTER_ARTICLES}</dd><!-- ENDIF -->

Article Counter