Irsah in Designs


Pagelist Block Most Popular Pages Mod Template




We received requests for special popular pages or most visited page for concrete5 theming. Through search in concrete5 forum, we encountered this code, provided by generous concrete5 members for that special functionality.

Using concrete5 Pagelist core block, adding these simple mods will provide you the head start in output-ing the nescessary results required - most visited pages that is.

Thanks to OKHayat (the initial code author) and revised by Goesredy (2012), this PHP code snippet is still workable for concrete5 version 5.5.++. We often abuse codes snippets like this, gathered through concrete5 forums or web apps, to enhance, improvise  and refine functionality for our clients-friends concrete5 powered websites.

 

Popular Pages/Most Visited Mod Using the Pagelist Block

As Okhayat explains, the code snippet is "following custom SQL as a Page List block template". What this code do is to gather information from your concrete5 mySQL database, and render/populate visited pages click results based on that database, while using existing block (the Pagelist block) and creating a template for it.

Of course there are Add-Ons blocks like this Popular Page in concrete5 Marketplace, contributed by concrete5 community/members/developers, but the main reason we display it here is for our own reference and of course probably it could be useful for future projects/web builds.

Below and also in the downloaded files, included statements for you to customize this pagelist template block. We also included some CSS stylings, based on out previous projects to give you a head start.

The PHP code for Pagelist block template to populate popular/most visited pages (incl in template_folder_name/view.php)

 

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$num = count($cArray);
$limit = $num ? $num : 10; //Change integer to required links to display -current 10 pages
$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();
$pageList = $db->execute($mrSql);
?>

<!--Start Your CSS Stylings-->
<div class="s960_most_popular_page">

<ul>
<?php while ($pg = $pageList->fetchRow()) {
$curPage = Page::getByID($pg[cID]);
?>
<li><a href="<?=$this->url($curPage->getCollectionPath())?>"><?=$curPage->getCollectionName()?></a></li><? } ?>
</ul>
</div>
<div class="spacer"> </div>

 

This updated code snippet by Goesrady only populate popular/most visited pages from your mySQL database. It does not output/include your concrete5 system pages (Dashboard, Log-In page etc) in displaying the results.

And then the CSS for stying (as in template_folder_name/view.css)

 

.s960_most_read{display:block}
.s960_most_read ul{
border:1px solid #ccc;
padding:0;
margin:0;
border-radius:0.4em;
}
.s960_most_read li{
display:block;
margin-bottom:0px;
border-bottom:1px solid #ccc;
}
.s960_most_read a{
display:block;
border-right:1em solid transparent;
border-left:1em solid transparent;
border-bottom:0.5em solid transparent;
border-top:0.5em solid transparent; }
.s960_most_read a:hover{
background:#f0f0f0;
border-radius:0.4em;
}
.s960_most_read li:last-child{
border-bottom:none;
  

 

An example output and stylings for the popular page/most visited links you could see here in this blog. Of course you can style the links to suit your web page design, but like explain before, gives you the head start though.

However for newly built concrete5 websites, it is best to manually create sample pages and manually visit those pages repeatedly (in random order), giving a head start on mySQL database populating clicks-to/visited pages. After doing so, you can clear cache (via Dashboard > System & Setting > Cache Setting) and/or your browser cache (if required). View the output results.

 

How To Install/Upload Popular Pages Template

(Currently file download unavailable due to our websites upgrades but it will be activated soon)

Assuming you have access to your concrete5 website, with required permissions and you know folders and files locations/uploads for your concrete5 website system via FTP to your web host;

Download a copy of the required files and folder for the pagelist block here.

Download

  1. Unzip the files/folder and rename the folder ie "most_popular_page" (small caps with underscore for spaces)
  2. Note: This is a template folder which includes a view.php file and view.css file.
  3. Open your favourite FTP program and upload the unzipped folder to YOUR_DOMAIN/blocks/pagelist/templates
  4. If you do not have a folder name "pagelist" and/or "templates" in your blocks flder, please create one in small caps.
  5. Now go to your website > while logged in, manouver to required page for editing.
  6. In Edit mode > click an area where you want to insert a Pagelist block > select Pagelist > minimum entries is required for the block > click Save.
  7. Still in edit mode > select the Pagelist block you inserted/Saved > select template (drop down editing menu) > select the named folder (for the above example "Most Popular Page") you have just uploaded.
  8. Click Save and you may preview by using the Preview tab or click Publish This Page.
  9. Style to your desire//theme using page Edit mode > select block > the block Design editor. 

Hope these customizations will spice up you web pages or maybe your blog posts as required. If you have more functionality includes by uisng the above code, do share. We love to see it bloom and also watch how far a small snippet like this could do remarkable jobs.

Do take note that we are not associated with concrete5, the software or developers whatsoever.  We are just end users like you, builds sites, supporting the powerful software (and loving it) and giving back to the community. You can read our policy here.