Jump to content

Developer Documentation

Supporting page views in Content Items

Your content item can automatically track the number of times it is viewed by implementing the page view interface. Note that guest page caching may render the count inaccurate since a cached page won't increase the view count.


Implementing page view tracking

First, you need to implement the page view interface in your content item model, like so:

implements \IPS\Content\Views

Next, add a views key to your $databaseColumnMap, with the value being the name of the database column that stores the view count for your items.

Finally, be sure that the manage() method in your content item controller calls the parent manage() method:



Additional model methods available

array stats( [ boolean $includeFirstComment ] )

Returns an array of stats about the item, with a num_views key containing the view count.

  • $includeFirstComment (boolean, optional, default TRUE)
    Determines whether the first comment is counted in the item's comment count.

  Report Document

  • Create New...