An addon plugin to WP Analytify that adds new shortcode: analytify_top_content.

Why do I need it?

To show accurate most popular posts list without killing your server/database

Normally, top content / most popular posts are calculated by adding “+1” in database each time somebody visits certain post or page. This is fine, when there are not many visitors, but makes your database very busy once there are more visits. Caching? Either will stop counting of new visits, or will be passed by through javascript what will lead to heavy load again. But probably – as most of the sites – you’re using analytics. Right? And in analytics panel you can see most visited pages for certain date range. Why not use it instead of duplicating this existing feature on your website by yet another popular posts plugin? That’s exactly what we do here. To keep things simple and don’t repeat what was already done by numerous other plugins, we base our code on free WP Analytify plugin – this way you don’t have to authorize Analytics again if you’re already using it (… or you’ll get some extra analytics within WP admin panel once you install it).

How it works?

Shortcode allows users to fetch top pages from Google Analytics and show them as a list. Global options page allows you to exclude some particular pages across whole website if you’re using more than one shortcode on it. “Hostname” parameter was added to allow WPML / Polylang / other languages solutions work well (this way you can skip particular domain in particular place).

Technical details: when shortcode is fired – plugin will look for data stored in WordPress internal cache (transient). If no luck – new request through Analytify will fetch data from Analytics and keep it in transient for another visitors.

How will it look like?

As you wish! By default, it’s a list of titles with links. If you want to modify default outlook – simply copy “shortcode.php” file from templates directory to “wp-analytify-shortcodes” directory withing your (child) theme. If you want to have different outlook for different post types, simply add there “shortcode-POST_TYPE.php” file – for example “shortcode-post.php”.

Example of code to use in case you’d like to load additional post data, like featured image:


<ul>
<?php foreach($rows as $row): ?>
<li>
<?php
global $post;
//you can show thumbnail this way
echo get_the_post_thumbnail($row->getPostId(), 'thumbnail');
// you can load all post data this way
setup_postdata( $post );
//..and then load your template part
get_template_part('template-parts/some_template');
//don't forget to reset postdata!
wp_reset_postdata();
?>

</li>
<?php endforeach; ?>
</ul>

How to use?

Available parameters:

  • period – defines time period we want to get (like: “2 months”, “last month”, “last 3 weeks”). Required
  • to – when period does not contain a word “last” we need to define point in time which is the last day of required period (so 2 weeks to 2018-12-01 is between 2018-11-14 and 2018-12-01)
  • limit – number of rows we want to show
  • exclude-home-page – pass “yes” if you want to exclude home page (which gets the most number of views usually) from results
  • post-type – required post type in results
  • title-remove – text we want to remove from the page title
  • except-ids – post IDs we want to skip from the result
  • except-urls – post urls we want to skip from the result
  • hostname – adds ability to filter by hostname (i.e. page in different language). Useful if you use WPML, Polylang, or Multisite in different domain/subdomain mode and want to limit results to current domain only.
  • exclude-items – adds ability to exclude “parents”` or “children”. Useful for example if you want to show only top level pages or only popular child pages.

This plugin has global settings support for except-ids, except-urls and exclude-home-page options

**1.3.1 (2019-05-09)**
* FIX: Invalid class called for admin settings

**1.3.0 (2019-05-03)**
* NEW: Ability to exclude top pages or child pages
* IMPROVEMENT: Code refactoring

**1.2 (2019-01-15)**
    * NEW: Global options for Top Content shortode (found in Analytify -> Settings -> Shortcodes global settings)

**1.1 (2019-01-14)**
    * NEW: Possibility to exclude certain post IDs or urls from appearing in the result
    * NEW: Ability to select base hostname from Google Analytics (i.e. for different language pages)

**1.0 (2018-12-27)**
    * First release

Support available in Polish and English!

TMDb Pro – Movie & TV Show Details Plugin For The Movie Database

Google Analytics Top Content Widget with Analytify plugin

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Where does it come from?

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of “de Finibus Bonorum et Malorum” (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, “Lorem ipsum dolor sit amet..”, comes from a line in section 1.10.32.

Where can I get some?

There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.

Google Analytics Top Content Widget with Analytify plugin