User Tools

Site Tools


doc:tips:entry_views_in_the_lastentries_plugin

This is an old revision of the document!


Adding the number of views

to the FlatPress LastEntries plugin

Taken over from 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 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 .= '<li>';

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 .= "<a href=\"{$link}\">{$entry['subject']} ({$v})</a></li>\n";
 
		$count++; // <-- existing code, do not modify

The result is something like this:

The result is something like this

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

doc/tips/entry_views_in_the_lastentries_plugin.1677371968.txt.gz · Last modified: 2023/02/26 01:39 by fraenkiman

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki