Page 1 of 1

[Solved] Display most viewed article in CGBlog?

Posted: Thu Mar 12, 2015 2:54 am
by pwg
Hi,

Searched and can't see an obvious answer on how to provide a "most viewed" style option for sorting and displaying CGBlog posts.

I was wondering if I could use HitCounter to get the most visited pages, and use this info to display the most visited CGBlog posts?

In my CGBlog Detail template I added:

Code: Select all

{HitCounter key1="CGBlog" key2=$entry->id}
and I tried in a content section without any success.

Code: Select all

{HitCounter action=getmostvisited ndays=30 key1=CGBlog assign='theidlist'}
{foreach from=theidlist item=oneid}
  {CGBlog action=popular articleid=$oneid}
{/foreach}


Any ideas on how to make this work? Another way?

Thanks for any help.

Cheers,

Paul

Re: Display most viewed article in CGBlog?

Posted: Sat Mar 14, 2015 10:41 pm
by pwg
Can somebody let me know if I'm asking a stupid question, that I should know the answer too, or if there is an obvious way to do this that I've missed, or any suggestions on where to look?

Thanks for any help.

Cheers,

Paul

Re: Display most viewed article in CGBlog?

Posted: Sat Mar 14, 2015 11:09 pm
by Jo Morg
pwg wrote:Can somebody let me know if I'm asking a stupid question, that I should know the answer too, or if there is an obvious way to do this that I've missed, or any suggestions on where to look?
Well it's not a stupid question, but the code you started up with doesn't make sense...

Code: Select all

{foreach from=theidlist item=oneid}
  {CGBlog action=popular articleid=$oneid}
{/foreach}
Where does this come from? There isn't any hint on CGBlog Help page that this action exists at all.

However on HitCounter Help:
{HitCounter action=popular [key1=string [key2=string]] [limit=number] [popular_template=string]
Sooo.... without any foreach loop, whi don't you just try:

Code: Select all

{HitCounter action=popular key1='CGBlog'}
That might do the trick.... :)

Note: I didn't tested though, but I shouldn't be too far...

[Solved]Re: Display most viewed article in CGBlog?

Posted: Sun Mar 15, 2015 12:53 am
by pwg
Hi Jo, many many thanks for your help.

Instant results.

I came up with my odd code from an old forum question answered by Calguy - obviously I mangled the code - and answer.
http://forum.cmsmadesimple.org/viewtopic.php?t=37822

However, thanks again - very simple solution.

Cheers,

Paul