How to fetch the last added content


how fetch last added content to a summary page?

greetings perry

Use sortBy()

$newest = $site->index()->sortBy('created', 'desc');
$lastModified = $site->index()->sortBy('modified', 'desc');

What do you mean? Fetch only the last post of a series of posts? Or, as @Pascalmh suggests, sort all pages by date?

Perfect would be the last post of a series.

To get the last post of, let’s say, all posts in the “blog” folder:

$last = page('blog')->children()->visible()->sortBy('date', 'desc')->last();
$last = page('blog')->children()->visible()->sortBy('date', 'desc')->last(10)->title();

how get all children of ‘page’?


Use index() instead of children:

$last = page('blog')->index()->visible()->sortBy('date', 'desc')->last(10)->title();

or if all posts are below “news”:

$last = page('blog/news')->index()->visible()->sortBy('date', 'desc')->last(10)->title();

@texnixe thank you for your help!
are you sure last(10) it works?

$last = page('blog/news')->index()->visible()->sortBy('date', 'desc')->last(10)->title();

get one title

$last = page('blog/news')->index()->visible()->sortBy('date', 'desc')->title();

get all titles

last() returns the last page, it doesn’t take a param. You are looking for limit(10), but then you need a foreach to iterate through all pages.

This worked for me

foreach($site->index()->visible()->sortBy('modified', 'desc')->limit(5) as $items):
	echo "<a href=".$items->url().">".$items->title()."</a><br>";

Thanks for your help.