How to get latest pages?

In this example, we will read the list of latest publications and put it into the variable $TEST. We will then iterate through this list to print its sublists.

You can use this example to read database records that should be shown as latest publications.


Source Code

Please paste this code snippet into your template to see how it works.

Let's experiment with a template like tiny.news.feed/Themes/default/404.tpl by pasting code into it and then opening some non-existent page associated with that template.

<?php
    $TEST = $cms->getLatest();
    foreach ( $TEST as $type => $sublist ) {
        if ( $sublist ) {
            echo 'Publications of kind ' . $type . ' <br>';
            echo '---------------------------------- <br>';
            foreach ( $sublist as $item ) {
                echo $item['title'] . ' <br>';
            }
        }
    }
?>

Note that the $cms variable is a system pointer to your web application. And getLatest is a public method for reading the latest publications. If you are interested in the algorithm of this method, look at the file tiny.news.feed/Application.php.

Remark

The public method used above has two optional arguments:

The return value is a name-indexed list of sublists retrieved from the database.


How to get specific latest pages?

In the following code snippet, we will read a list of 4 latest news and 4 articles and put it into the variable $TEST. We will then iterate through this list to print its sublists.

<?php
    $TEST = $cms->getLatest(4, [ 'news', 'articles' ]);
    foreach ( $TEST as $type => $sublist ) {
        if ( $list ) {
            echo 'Publications of kind ' . $type . ' <br>';
            echo '---------------------------------- <br>';
            foreach ( $sublist as $item ) {
                echo $item['title'] . ' <br>';
            }
        }
    }
?>

* This page is a demo post designed to display page content for testers. You need delete this page when you run the website in production mode.