Snippet · Mecha CMS

Code snippet collection for developers.

Basic Popular Posts

Author: Taufik Nurrohman · 442 Views

Tweet

Show list of most viewed pages.

Requires page view plugin.

<?php

$_path = PAGE . DS . 'article';
$_chunk = 7;

echo '<h3>Popular Posts</h3>';
if ($_pages = Get::pages($_path, 'page', [-1, 'view'])) {
    echo '<ul>';
    foreach (Anemon::eat($_pages)->chunk($_chunk, 0) as $_page) {
        $_page = new Page($_page['path']);
        echo '<li>' . HTML::a($_page->title, $_page->url) . ' (' . $_page->view . ')</li>';
    }
    echo '</ul>';
} else {
    echo '<p>No views yet.</p>';
}

?>
  • $_path → Select which page folder you want to list.
  • $_chunk → How many pages you want to list.

0 Comments

No comments yet.