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

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

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

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.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.