Popular posts for “Count per Day” WordPress plugin

popularpostsLeaseWeb Labs runs on WordPress and we are using the “Count per Day” plugin to keep track of our visitors. One big advantage of Count per Day is that it does not use cookies, but counts the amount of unique IP addresses per day. These are reported as “visitors”, while the amount of page views are reported as “reads”. In our experience this is a very simple and reliable way of measuring the visitors on our site. Especially when you enable the option “Cache: Count visits with ajax” in the Settings, because that will prevent bots from showing up in the statistics.

Some posts are better and thus more popular than other posts. When people visit your site for a certain post, they may also be interested in other popular posts. This is why we wanted the most popular posts listed in the sidebar (as you can see on the left). Since the popularity of posts is changing all the time and we did not feel like maintaining a static list of posts in menu. Count per Day has a the shortcode “CPD_MOST_VISITED_POSTS” to generate this list for you. Unfortunately this code generates the list including numbers and a heading. This is not exactly the way we like it and thus we created a WordPress widget for our (and your) convenience.

The widget can be simply dragged into a widget area and allows you to:

  • Set the title for the list
  • Set the amount of days to take into account
  • Set the maximum number of items in the list
  • Show/hide the counts for the selected period
  • Show/hide the header that explains the counts

We contacted Tom Braider (the author of this fantastic plugin) and we hope he will include the widget in a next version. Until then you can install the widget by adding the following code to “widgets.php” using the theme editor:

if (isset($count_per_day)) {

// Creating the widget
class PopularPostsWidget extends WP_Widget {

  function __construct() {
      // Base ID of your widget
      // Widget name will appear in UI
      'Popular Posts',
      // Widget description
      array( 'description' => 'Count-Per-Day Popular Posts'));

  // Creating widget front-end
  // This is where the action happens
  public function widget( $args, $instance ) {
    $title = apply_filters( 'widget_title', $instance['title'] );
    $days  = $instance['days' ]+0;
    $limit = $instance['limit']+0;
    $head  = $instance['head' ]?true:false;
    $count = $instance['count']?true:false;
    // before and after widget arguments are defined by themes
    echo $args['before_widget'];
    if ( ! empty( $title ) ) {
      echo $args['before_title'] . $title . $args['after_title'];
    // This is where you run the code and display the output
    global $count_per_day;
    $html = $count_per_day->getMostVisitedPosts($days, $limit, 1, 1, 1);
    if (!$head ) $html = preg_replace('/<small>[^<]*<\/small>/','',$html);
    if (!$count) $html = preg_replace('/<b>[^<]*<\/b>/','',$html);
    echo $html;
    echo $args['after_widget'];

  // Widget Backend
  public function form( $instance ) {
    $title = isset($instance['title'])?$instance['title']:'Popular Posts';
    $days  = isset($instance['days' ])?$instance['days' ]:'7';
    $limit = isset($instance['limit'])?$instance['limit']:'10';
    $head  = isset($instance['head' ])?$instance['head' ]:false;
    $count = isset($instance['count'])?$instance['count']:false;
    // Widget admin form
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
<label for="<?php echo $this->get_field_id( 'days' ); ?>"><?php _e( 'Days:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'days' ); ?>" name="<?php echo $this->get_field_name( 'days' ); ?>" type="text" value="<?php echo esc_attr( $days ); ?>" />
<label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Limit:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
<label for="<?php echo $this->get_field_id( 'head' ); ?>"><?php _e( 'Show header:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'head' ); ?>" name="<?php echo $this->get_field_name( 'head' ); ?>" type="checkbox" <?php echo $head?'checked="checked"':'' ?> />
<label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show counters:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" type="checkbox" <?php echo $count?'checked="checked"':'' ?> />

  // Updating widget replacing old instances with new
  public function update( $new_instance, $old_instance ) {
    $instance = array();
    $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    $instance['days' ] = ( ! empty( $new_instance['days' ] ) ) ? strip_tags( $new_instance['days' ] ) : '';
    $instance['limit'] = ( ! empty( $new_instance['limit'] ) ) ? strip_tags( $new_instance['limit'] ) : '';
    $instance['head' ] = ( ! empty( $new_instance['head' ] ) ) ? strip_tags( $new_instance['head' ] ) : '';
    $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? strip_tags( $new_instance['count'] ) : '';
    return $instance;
} // Class PopularPostsWidget ends here

// Register and load the widget
add_action( 'widgets_init', function (){ register_widget('PopularPostsWidget'); });


LeaseWeb Labs celebrates a successful 2013

Today we share with you some insights in our LeaseWeb Labs traffic of 2013. The post also shows which tools we use to analyze the traffic (the underlined parts of the titles are links). Some facts:

  • We published 72 articles in 2013, where we published 29 articles in 2012.
  • The amounts of articles posted per month in 2013 from (Jan-Dec) are: 6,5,6,4,5,8,8,6,4,6,5,9, were that series was 2,2,0,0,4,2,3,5,1,2,4,4 in 2012.
  • At the end of 2012 we had about 4-5k unique visitors per month and now at the end of 2013 we are at 40-50k!
  • We are very proud that we reached 1500 unique visitors per day on average in December.
  • Google Webmaster Tools shows that about one third of those visitors are sent to us by Google (Search).

Check out screenshots from our statistics below.

Statistics from Count-per-day





Statistics from Google Webmaster Tools



Statistics from Alexa



I want to thank you all for helping to make this blog a success, whether it was by reading, commenting, writing, promoting or sharing article feedback and new ideas. It is much appreciated!

Happy holidays and keep visiting in 2014!