Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Hit/views counter

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2429 Views
  • baba-papa
    Avatar
    Community Member
    279 Posts

    Hit/views counter Link to this post

    I programmed a hit counter for my blog. I always wondered if anyone reads my blog posts ;-) Now I know for sure.
    May be this is useful to anyone else.
    This is the method (BlogEntry_Controller.php):

    function incViews() {
    if(Session::get('BlogViewed-' . $this->ID) == false){
    Session::set('BlogViewed-' . $this->ID, 'true');
    $this->Views++;
    $SQL_numViews = Convert::raw2sql($this->Views);
    DB::query("UPDATE BlogEntry_Live SET Views = '$SQL_numViews' WHERE ID = $this->ID");
    }
       }


    I gets called in the init():

       function init() {
          parent::init();
          $this->incViews();
          Requirements::themedCSS('blog');
       }


    I stole this idea from the FORUM-Module. Please tell me what you think about this feature.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Hit/views counter Link to this post

    I always wondered if anyone reads my blog posts ;-)

    Well if you want some better statistics http://www.google.com/analytics/ or any other web statistics package would provide much more useful data.

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Hit/views counter Link to this post

    Thanks for your hint. I´m not familiar with google analystics yet. It will be my next challenge to work with it.

    Obviously my work is useless to others, but I learned some more things about SS.

    2429 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.