===== Adding the number of views to the FlatPress LastEntries plugin =====
Taken over from [[https://www.igorkromin.net | Igor Kromin]]
==== Description ====
This tutorial shows you how to use the LastEntries plugin and the PostViews plugin to see at a glance how many views the entries have had.
This hack requires the PostViews plugin to be enabled.
==== Procedure ====
Changed the file //[[https://github.com/flatpressblog/flatpress/blob/master/fp-plugins/lastentries/plugin.lastentries.php | fp-plugins/lastentries/plugin.lastentries.php]]// as follows:
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: reads out file from PostViews plugin ---
$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: reads out file from PostViews plugin ---
$string .= '';
Then, a few lines further, the line directly above the ''$count++'' line must be changed as follows:
// --- modified line below: adding the number of views ---
$string .= "{$entry['subject']} ({$v})\n";
$count++; // <-- existing code, do not modify
The result is something like this:
{{:res:plugins:ikromin:Adding_the_number_of_views_to_the_LastEntries_plugin.png?240|The result is something like this}}
The entry view count is shown in brackets next to the entry name.