Page List / Popular Pages
Permalink 6 users found helpfulIs there anyway in C5 to create a list of the most viewed pages – like a list of popular pages which updates itself by the amount of views they get? Then maybe display say a top 5?
Could you do this with the page list block?
If anyone knows how to do this that would be a great help!
Thanks
Tim
Thanks for sharing this.
Can I just check – when I implement the custom template my page list disappears completely... is this because none of the pages have been viewed yet to make them the most popular? and the list will populate once some pages have been viewed?
Hope that makes sense.
Thanks
Tim
EDIT: Also, the count doesn't include pages that have sub pages. You can remove 'AND cChildren = 0' from the query to include those.
Do you know how long it takes until the popular pages appear?
Thanks
Tim
You may want to add a condition to show a simple message instead of an empty block.
Parse error: syntax error, unexpected $end in C:\wamp\www\my_site\blocks\page_list\templates\most_read.php on line 21
when I try to use this... any ideas?
Thanks so much for this! Very handy.
How could I limit results to just pages of a certain page type?
WHERE cParentID > 0 AND cChildren = 0 AND pt.ctIsInternal = 0 AND pt.ctID = 4 AND p.cIsActive = 1
Can someone identify what the correct WHERE line would be?!
Thanks in advance,
Joe
I also get the error:
Parse error: syntax error, unexpected $end in C:\wamp\www\my_site\blocks\page_list\templates\most_read.php on line 21
I tried almost everything to kill that...
Have you got an idea?
Thanks
Mathias
My issue was with:
WHERE cParentID = $cParentID and cChildren = 0
seems SQL didn't like the variable $cParent. I used Firebug and poked around the DOM and found my homepage ID was 0. I replaced the variable with the ID# and it worked. I then decided that the homepage would get a lot of hits anyway and I wanted it removed from the list. My homepage ID was 0, so I set the line to read as follows:
WHERE cParentID > 0 and cChildren = 0
This fixed my issue. Just an idea to try for others having problems, no promises, but I figured someone might benefit from it somewhere along the line.
I just modify okhayat codes for not display internal pages and trashed page.
Page limit come from page limit on page list edit.
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $num = count($cArray); $limit = $num ? $num : 10; $mrSql = "SELECT cv.cID, COUNT(*) Visits FROM CollectionVersions cv JOIN Pages p ON cv.cID = p.cID JOIN PageStatistics ps ON cv.cID = ps.cID JOIN PageTypes pt ON cv.ctID = pt.ctID WHERE cParentID > 0 AND cChildren = 0 AND pt.ctIsInternal = 0 AND p.cIsActive = 1 GROUP BY ps.cID ORDER BY Visits DESC LIMIT $num"; Loader::model('page_list'); $db = Loader::db();
defined('C5_EXECUTE') or die(_("Access Denied."));
$num = count($cArray);
$limit = $num ? $num : 10;
$mrSql = "SELECT cv.cID, COUNT(*) Visits
FROM CollectionVersions cv
JOIN Pages p ON cv.cID = p.cID
JOIN PageStatistics ps ON cv.cID = ps.cID
JOIN PageTypes pt ON cv.ctID = pt.ctID
WHERE cParentID > 0 AND cChildren = 0 AND pt.ctIsInternal = 0 AND p.cIsActive = 1
GROUP BY ps.cID
ORDER BY Visits DESC
LIMIT $num";
Loader::model('page_list');
$ih = Loader::helper('image');
$db = Loader::db();
$pageList = $db->execute($mrSql);
?>
<div class="ccm-page-list">
<ul >
<?php while ($pg = $pageList->fetchRow()) {
$curPage = Page::getByID($pg[cID]);
$img = $page->getAttribute('thumbnail');
$thumb = $ih->getThumbnail($img, 60, 60, false);
?>
<li>
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<a href="<?=$this->url($curPage->getCollectionPath())?>"><?=$curPage->getCollectionName()?></a></li><? } ?>
</ul>
</div>
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $num = count($cArray); $limit = $num ? $num : 10; $mrSql = "SELECT cv.cID, COUNT(*) Visits FROM CollectionVersions cv JOIN Pages p ON cv.cID = p.cID JOIN PageStatistics ps ON cv.cID = ps.cID JOIN PageTypes pt ON cv.ctID = pt.ctID WHERE cParentID > 0 AND cChildren = 0 AND pt.ctIsInternal = 0 AND p.cIsActive = 1 GROUP BY ps.cID ORDER BY Visits DESC LIMIT $num"; Loader::model('page_list'); $db = Loader::db();
Does that code work for you?
I cannot get it work. Have you got an idea, what I am doing wrong?
Best Mathias
The code could be way out of step with the schema for the database in current c5 versions.
So have a look inside the core page list class for the current version of c5 and see if that provides clues about changes you would need to make to the example code.
You should also consider using the core page list class and extending it with just the snippet you need for popular pages. That approach would be considerably more future proof.
You may also be able to do this using my Uber List and Magic Data addons.
http://www.concrete5.org/marketplace/addons/uber-list/...
http://www.concrete5.org/marketplace/addons/magic-data/...
cParentID > 0
Change to this :
cParentID = $cParentID
best regards, Roland
It will by default display the top ten, unless you choose the number of pages you want to display.