Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
One of the things I wanted to have on this blog was the ability to see how many views there were for the entries in one quick glance. The LastEntries plugin gives the list of last 10 entries, but does not show how many times each one has been viewed.

Digging into the PostViews plug, the code is quite simple, it just loads the view counter file for the entry and displays it's content.

This hack requires the PostViews plugin to be enabled.


I've modified the fp-plugins/lastentries/plugin.lastentries.php file like so: Note that the first and last lines shown here are already in the file, so only the lines between the comments are relevant:
$link = get_permalink($id);
// --- new code: igorkromin.net ---
$dir = entry_dir($id);
if (!$dir) return;
$f = $dir . '/view_counter' .EXT;
$v = io_load_file($f);
if ($v===false){
$v = 0;
}
// --- end new code: igorkromin.net ---
$string .='<li>';


Then a few lines down I've modified the line just above the $count++ line like this:
// --- modified line below: colorsin.com ---
$string .= "<a href="{$link}">{$entry['subject']} ({$v})</a></li>n";
$count++; // <-- existing code, do not modify


The result is something like this:
lastentries_views.png


The entry view count is shown in brackets next to the entry name.

-i

Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...