Counting views

Hi all, I'm working on counting total views of blog posts but my coding seems to be missing something. Can anyone shed some light on the issue?


$blogs = elgg_get_entities(array('types' => 'object','subtypes' => 'blog', 'limit' => 10, 'owner_guid' => $user_id));


foreach($blogs as $blog){

$count_annotations = $blog->countAnnotations("blogview"); 


$total_views = array_sum(array($blogs->$count_annotations));

I'm sure it's something obvious, but I can't see what's not working properly. The output is 0, but on my test site the blog posts do have at least 10 views combined.

EDIT: Sorry I should have mentioned, what I'm trying to do is get the total count of the views for all of his blog posts. So example is below:

Blog post 1 (Views 5)
Blog post 2 (Views 8)
Blog post 3 (Views 12)

Total_views = 25

  • If you're trying to get the number of times the blog post has been viewed (looked at) by users -> this is not stored any where.

  • Nope, I've already created the annotation called blogviews which is working fine.

    The count for each individual blog post is working fine, I'm having trouble combining all the counts together into a total blogviews count for each user of his blog posts.

  • This is the coding to annotate the blogs:

    $page_owner = page_owner_entity();

    $current_count = $vars['entity']->getAnnotations("blogview");


    $vars['entity']->annotate('blogview', 1, 2);

    } else {

    $updateable = true;


    if(get_loggedin_user()->getGUID() == $page_owner->getGUID()){

    // dont count own profile visits

    $updateable = false;




    update_annotation($current_count[0]->id,  "blogview", ($current_count[0]->value + 1), $current_count[0]->value_type,$current_count[0]->owner_guid, $current_count[0]->access_id); 



  • Would like a profile view counter, do we have one? It shouldn't count your own views...

  • This is the code taken from profile_counter plugin (provided with old 3column riverdashboard) and the above code does not count your own views.