- [init_view_count] Shortcode
- Basic usage
- Supported attributes
- Example
- [init_view_list] Shortcode
- Basic usage
- Supported attributes
- Example: show most viewed posts in the “news” category this week
- Overriding the display template
- Override structure
- Shortcode [init_view_ranking]
- Basic usage
- Supported attributes
- Example
- Advanced tips
[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,monthtime: if set totrue, 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,monthtemplate: layout style (default:sidebar). You can override this in your theme. See below.category: filter by category slugtag: filter by tag slugtitle: heading shown above the list (settitle=""to hide)class: custom CSS classes to addorderby/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,monthnumber: number of posts to show per tab (default: 5)class: optional CSS class for the wrapperpost_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_keyfilter to dynamically change the meta key based on context - Use the
init_plugin_suite_view_count_query_argsfilter to modify the WP_Query used by the shortcode - Use the
init_plugin_suite_view_count_empty_outputfilter 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