Snippet · Mecha CMS

Code snippet collection for developers.

Basic Recent Posts

Author: Taufik Nurrohman · 417 Views

Tweet

Show list of pages in reverse order by time.

<?php

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

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

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

0 Comments

No comments yet.