Most Read/View Articles
10 posts by 3 authors in: Forums > CMS Builder
Last Post: February 13, 2012 (RSS)
By aharrow - December 31, 2008
Thanks.
Re: [aharrow] Most Read/View Articles
By Dave - December 31, 2008
Yes, it's a two step process. First you need to track hits or views for each record. Then you can sort on that field.
Create a field called 'hits' (or whatever you want to call it) add this in your page. Then use this code. This first field is the tablename, the second field is the fieldname, and the third field is the record number
<?php incrementCounterField('news', 'hits', $newsRecord['num']); ?>
Once you have that working create a list viewer that sorts like this:
'orderBy' => 'hits+0 DESC',
Hope that helps!
interactivetools.com
Re: [Dave] Most Read/View Articles
By aharrow - December 31, 2008
Also the code "[font "Verdana"]<?php incrementCounterField('news', 'hits', $newsRecord['num']); ?> " can it be placed anywhere in the body of article.[/#000000][/#ff0000]
[font "Verdana"]As it stands right now this is a sample of my code[/#000000] [/#ff0000]
[font "Verdana"]list($featuredRecords, $featuredMetaData) = getRecords(array(
'tableName' => 'featured',
'limit' => '2',
'orderBy' => 'date DESC, title',
'where' => 'archive = 0',
));[/#ff0000]
[font "Verdana"]?>[/#ff0000]
[font "Verdana"]do i put the increment code on this (list) page or on the details page
Thanks
Re: [aharrow] Most Read/View Articles
By Dave - December 31, 2008
Hope that helps!
interactivetools.com
Re: [Dave] Most Read/View Articles
By aharrow - January 5, 2009
Re: [aharrow] Most Read/View Articles
By aharrow - January 5, 2009
I got the intial code working <?php incrementCounterField('press_news', 'hits', $press_newsRecord['num']); ?>[/#ff0000]
However, I have got multiple sections and really wanted to do an "includes page" with the most read articles (combination of different sections).
How would I be able to combine my results to show on one page. example Top 5 Most read articles <?php incrementCounterField('press_news', 'hits', $press_newsRecord['num']); ?> and [/#000000][/#ff0000]<?php incrementCounterField('featured', 'hits', $featuredRecord['num']); ?> [/#ff0000]
Thanks in advance.
Re: [aharrow] Most Read/View Articles
By Dave - January 6, 2009
There's a few ways to do it. The simplest would be if you had all your articles in the same table and a field that let you specify where they should be displayed (eg: press_news, featured, etc).
Otherwise, you could show the top 5 articles from each section. To show the top five from either section you'd need to write some custom php. You'd need to load the top 5 from both and combine the arrays, then sort on hits and only show the top 5. This could leave you with all articles from one table and none from the other though. So it's possible, but a bit more complex.
Hope that helps. Showing top 5 from each table is the simplest, or merging all your articles into one table.
interactivetools.com
Re: [Dave] Most Read/View Articles
I have got the hit counter field setup and working, which I am really pleased about. However, I am wondering if it's possible to make the field visible but not editable by users in cmsAdmin?
It seems if I make it a System Field then it just hides the field for all users except the Admin. Ideally, I'd like to make the hit counter field visible to all users but not editable, like the createdDate. The Admin should be able to edit the field though. Is that possible?
Thanks,
Greg
Re: [gversion] Most Read/View Articles
By Dave - February 13, 2012
We don't have an official way to do that, but try this undocumented method:
- Go to the "Field Editor" for your section
- Create a new "Separator" field
- Set the type to HTML with this content:
<tr>
<td>Hits</td>
<td><?php echo @$RECORD['num'] ?></td>
</tr>
- replace 'num' with the name of your hit counter field, eg: 'hits'
For some of the content in the field editor we make a variable called $RECORD available with the values of the current record so you can display them back if needed.
Hope that helps, let me know if that works for you.
interactivetools.com
Re: [Dave] Most Read/View Articles
Thanks for your help! That's a very nice workaround.
Regards,
Greg