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:

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


Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...