User Stats: Post Page View Counter

Link: https://support.brilliantdirectories.com/support/solutions/articles/12000106692

This guide explains how to display a Post Page View Counter for posts added by members. Built-in Brilliant Directories variables can be used to show how many times a post has been viewed across different timeframes.


Available View Counter Variables

Two variables are available to control the type of view count that will display:

VariableWhat It Shows
%stat_view_post%Total Views – Total number of times the post has been viewed since creation.
%stat_view_post__current_month%Monthly Views – Views received during the current calendar month.


Example Output

  • Total Views: 1523
  • Monthly Views: 47

These statistics provide members with insight into how their content is performing.


Tips

  • Counters update automatically without additional setup.
  • View counts can be styled using HTML or CSS to match the site design.
  • Displaying view statistics can help increase member engagement and encourage more posting.

Understanding Post Types

There are two categories of post interactions tracked by the system: multi-image post clicks and single-image post clicks.

Multi-Image Post Clicks

These post types can contain multiple images.

  • Photo Albums
  • Products
  • Digital Products
  • Properties
  • Classifieds

Single-Image Post Clicks

These post types contain a single primary image.

  • Videos
  • Articles
  • Jobs
  • Events
  • Coupons
  • Audios
  • Discussions

Implementation by Content Type

The last parameter in the function call determines the content type being tracked:

  • '0' for Multi-Image Posts (Groups)
  • '1' for Single-Image Posts

A. Multi-Image Post Views (Last Parameter: '0')

Total Views

<div class="module">
    <?php if($group['group_id'] > 0){ ?>
        <strong>Total Views<hr></strong>
        <?php echo processProfileAnalyticsStats('%stat_view_post%', $group['user_id'], $w, $group['group_id'], '0'); ?>
    <?php } ?>
</div>

Monthly Views

<div class="module">
    <?php if($group['group_id'] > 0){ ?>
        <strong>View Monthly Views<hr></strong>
        <?php echo processProfileAnalyticsStats('%stat_view_post__current_month%', $group['user_id'], $w, $group['group_id'], '0'); ?>
    <?php } ?>
</div>

B. Single-Image Post Views (Last Parameter: '1')

Total Views

<div class="module">
    <?php if($post['post_id'] > 0){ ?>
        <strong>Total Views<hr></strong>
        <?php echo processProfileAnalyticsStats('%stat_view_post%', $post['user_id'], $w, $post['post_id'], '1'); ?>
    <?php } ?>
</div>

Monthly Views

<div class="module">
    <?php if($post['post_id'] > 0){ ?>
        <strong>View Monthly Views<hr></strong>
        <?php echo processProfileAnalyticsStats('%stat_view_post__current_month%', $post['user_id'], $w, $post['post_id'], '1'); ?>
    <?php } ?>
</div>

Example: Creating a View Counter Widget

A custom widget can be created to combine both multi-image and single-image view counts for total and monthly views. Here is how to display it.


    1. Create a New Widget. Add the following code:
      This code automatically displays view statistics for both multi-image posts (Groups) and single-image posts. It checks whether the page is showing a group or a standard post, retrieves the total and monthly view counts, and only displays the statistics if actual data exists. When no views are recorded, the entire module stays hidden. This allows the same widget to be added to any sidebar and used across all post types without further customization.
    2. <?php
      // ----------------------------------
      // GROUP STATS
      // ----------------------------------
      $showGroup = !empty($group['group_id']);
      $groupTotal = 0;
      $groupMonth = 0;
      
      if ($showGroup) {
          $groupTotal = processProfileAnalyticsStats('%stat_view_post%', $group['user_id'], $w, $group['group_id'], '0');
          $groupMonth = processProfileAnalyticsStats('%stat_view_post__current_month%', $group['user_id'], $w, $group['group_id'], '0');
      }
      
      // ----------------------------------
      // POST STATS
      // ----------------------------------
      $showPost = !empty($post['post_id']);
      $postTotal = 0;
      $postMonth = 0;
      
      if ($showPost) {
          $postTotal = processProfileAnalyticsStats('%stat_view_post%', $post['user_id'], $w, $post['post_id'], '1');
          $postMonth = processProfileAnalyticsStats('%stat_view_post__current_month%', $post['user_id'], $w, $post['post_id'], '1');
      }
      
      // ----------------------------------
      // SHOW ONLY IF ANY STAT EXISTS
      // ----------------------------------
      if (
          ($showGroup && ($groupTotal || $groupMonth)) ||
          ($showPost && ($postTotal || $postMonth))
      ) {
      ?>
      <div class="module">
          <h4><strong>Content Statistics</strong></h4>
      
          <?php if ($showGroup) { ?>
      
              <?php if (!empty($groupTotal)) { ?>
                  <p><strong>Total Views:</strong> <?php echo $groupTotal; ?></p>
              <?php } ?>
      
              <?php if (!empty($groupMonth)) { ?>
                  <p><strong>Monthly Views:</strong> <?php echo $groupMonth; ?></p>
              <?php } ?>
      
          <?php } ?>
      
          <?php if ($showPost) { ?>
      
              <?php if (!empty($postTotal)) { ?>
                  <p><strong>Total Views:</strong> <?php echo $postTotal; ?></p>
              <?php } ?>
      
              <?php if (!empty($postMonth)) { ?>
                  <p><strong>Monthly Views:</strong> <?php echo $postMonth; ?></p>
              <?php } ?>
      
          <?php } ?>
      </div>
      <?php } ?>
    3. Go to Toolbox → Sidebar Manager.
    4. Edit or customize Post Single Page Sidebar.


    5. Add the widget by searching for its name (e.g., Public View Counter).
    6. Drag and drop it into the desired position, click Save Changes.

    7. Once saved, the view counter will display on post detail pages. This example can be previewed on all post detail pages that use the same sidebar. If a different sidebar is used, the widget can be added there as well.