Skip to content

1. Using WPP on posts & pages

Héctor Cabrera edited this page Jan 27, 2024 · 29 revisions

WordPress Popular Posts (WPP from now on) can be inserted into your posts and/or pages either via the [wpp] shortcode or, if you're using the Block editor (a.k.a. Gutenberg) there's also a WPP block that you can insert into your content.

The WordPress Popular Posts block

To quote the official documentation, "Blocks are the components for adding content in the new WordPress block editor." If you're still not familiar with the new editor you can learn more about it here: WordPress Block Editor.

Plugin version 5.4.0 introduced the WordPress Popular Posts block for everyone (it was available before but only as an experimental feature).

The WordPress Popular Posts block works just like the classic WordPress Popular Posts widget. All of the classic widget's features are available to the WPP block as well so if you have used the WordPress Popular Posts widget before you will find that the block is essentially the same thing. Only difference being is that you can use the block almost anywhere on your site (posts, pages, etc), not just on your site's sidebar!

For more details see WordPress Popular Posts now supports the Block Editor.

Shortcodes

Shortcodes are macro codes that allow users (that's you!) to insert bits of predefined functionalities into post/page content.

WordPress Popular Posts takes advantage of this feature so you can for example insert a list of popular posts on a Hall-of-Fame page or in the middle of a blog post so your readers can see what's popular / trending on your website at the moment; or maybe render the views count of a post/page somewhere.

These are the shortcodes that are currently being included with the plugin:

The [wpp] shortcode

Without any parameters the [wpp] shortcode will list the most viewed posts (up to 10) within the last 24 hours. To customize the shortcode (eg. change the number of posts, hide/show views count, etc.) have a look at the full list of parameters.

For example, this shortcode would display the top 5 viewed posts from the last 7 days:

[wpp range='last7days' limit=5 stats_views=1 order_by='views']

And this one would output the 10 most commented posts from the last 30 days:

[wpp range='last30days' stats_comments=1 order_by='comments']

The [wpp] shortcode and the Block Editor (a.k.a. Gutenberg)

If you're using the Block Editor on your website you'll want to use the Shortcode Block to insert the [wpp] shortcode, or any shortcode really, into your post / page.

The [wpp_views_count] shortcode

By default, and when not using any parameters with it, the [wpp_views_count] shortcode will return the total views count of the current post / page.

Parameters:

  • post_id (integer), the ID of the post / page. If not set, the shortcode will attempt to render the views count of the current post / page.
  • range (string), the time range of the views count. Accepted values: all (default), last24hours, last7days, last30days, custom.
  • time_unit (string), specifies the time unit of the custom time range (eg. [wpp_views_count range='custom' time_quantity=12 time_unit='hour']). Accepted values: hour, day, week, month.
  • time_quantity (integer), specifies the number of time units of the custom time range (eg. [wpp_views_count range='custom' time_quantity=12 time_unit='hour']).
  • number_format (integer | string), whether to format or not the views count (eg. 1,234 views when enabled, or 1234 views when disabled). Accepted values: 1 (enable, default value), 0 (disable), 'prettify' (prettifies the views count string, eg. 1.2k views).
  • include_views_text (integer), whether to include the "views" text with the views count (eg. 1,234 views) or not (eg. 1,234). Accepted values: 1 (enable, default value), 0 (disable).

Usage example:

[wpp_views_count] will render the total views count (eg. 1,200 views) of the current post / page.

[wpp_views_count post_id=57] will render the views count (eg. 98 views) of post / page ID 57.

[wpp_views_count range='last7days'] will render the views count (eg. 5 views) from the last 7 days of the current post / page.

[wpp_views_count number_format=0 include_views_text=0] will render the views count (eg. 1200) of the current post / page without number formatting nor the "views" text.