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

| Views: 4418
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.


Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...