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. AndgetLatest
is a public method for reading the latest publications. If you are interested in the algorithm of this method, look at the filetiny.news.feed/Application.php
.
Remark
The public method used above has two optional arguments:
- The
$size
parameter is intended to specify the capacity of each sublist.
The default size is 6 (that is, 2 * 3 publications).
- The
$filter
parameter is intended to provide a list containing only names of specific kind.
The default value is an empty list for reading the latest publications of any kind.
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.