Using Shortcodes in Init View Count – Flexible View Display

The Init View Count plugin provides two powerful shortcodes to display view counts and popular post lists. This article will guide you through using [init_view_count] and [init_view_list], with real-world examples and interface customization tips.

Using Shortcodes in Init View Count – Flexible View Display

[init_view_count] Shortcode

Note: This shortcode only works inside a single post page, where the $post global is available.

Basic usage

[init_view_count]

Supported attributes

  • format: how to display the view count. Options: formatted (default), raw, short (e.g. 1.2k)
  • field: which view range to display. Options: total, day, week, month
  • time: if set to true, shows how long ago the post was published (e.g. “3 days ago”)

Example

[init_view_count format="short" field="week" time="true"]

→ Displays the weekly view count in short format, along with time since published.

[init_view_list] Shortcode

Used to display a list of most viewed posts. Can be placed in sidebars, footers, inside posts, or widgets.

Basic usage

[init_view_list]

Supported attributes

  • number: number of posts to display (default: 10)
  • page: show a specific page of results (e.g., page="2" for the next set). Note: automatic pagination is not currently supported.
  • post_type: post type to query (default: post)
  • range: time range for view count: total, day, week, month
  • template: layout style (default: sidebar). You can override this in your theme. See below.
  • category: filter by category slug
  • tag: filter by tag slug
  • title: heading shown above the list (set title="" to hide)
  • class: custom CSS classes to add
  • orderby / order: control result sorting (e.g., orderby="meta_value_num", order="DESC")
  • empty: content to display if there are no matching results

Example: show most viewed posts in the “news” category this week

[init_view_list range="week" category="tin-tuc" number="6" template="grid" title="Most Viewed News"]

→ Displays the 6 most viewed posts this week from the tin-tuc category, using the grid layout with the heading “Most Viewed News”.

Overriding the display template

You can override the layout template for each view list, similar to how WooCommerce handles template overrides.

Override structure

your-theme/init-view-count/view-list-[template].php

For example, to override the grid layout, create this file in your theme:

your-theme/init-view-count/view-list-grid.php

If the template is not found in the theme, the plugin will fall back to its default view-list-sidebar.php file.

Shortcode [init_view_ranking]

Displays a tabbed ranking of most viewed posts by day, week, month, or all-time. Ideal for sidebars, featured sections, or homepage tabs.

Basic usage

[init_view_ranking]

Supported attributes

  • tabs: comma-separated list of ranges to show. Default: total,day,week,month
  • number: number of posts to show per tab (default: 5)
  • class: optional CSS class for the wrapper
  • post_type: filter by specific post type (e.g. post, page, etc.)

Example

[init_view_ranking tabs="day,week" number="4" class="uk-margin"]

→ Displays two tabs: today’s and this week’s most viewed posts, 4 per tab.

Includes built-in skeleton loader and lazy loads via REST API — ideal for SPAs and heavily cached pages.

Advanced tips

  • Use the init_plugin_suite_view_count_meta_key filter to dynamically change the meta key based on context
  • Use the init_plugin_suite_view_count_query_args filter to modify the WP_Query used by the shortcode
  • Use the init_plugin_suite_view_count_empty_output filter to customize the output when no posts are found
  • You can use these shortcodes in widgets by adding them to an HTML block or using a shortcode-compatible widget plugin

Comments


  • No comments yet.

Web-Based Tools

Press Ctrl + \ on desktop, or swipe left anywhere on mobile.

Login