How to get URL of latest post

Post Reply
jonathanholvey
Ssr. Bludit
Posts: 23
Joined: Mon May 22, 2017 10:15 pm

In Bludit 2 you can access the $pages array on the home page, which gives access to properties such as title, URL etc.

Is there a way to do the same from any page? Specifically, I'm trying to get the URL of the latest published post (page), so I can use it as a direct link in my theme's navigation menu.
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

Hi,
this is for the pages with the type published, you need to use getList because this type is paginated.

Code: Select all

<?php

$pageNumber = 1; // First page number
$amountOfItems = 5; // Latest 5 items
$onlyPublished = true;
$listOfPages = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);

// Take only the keys
$listOfKeys = array_keys($listOfPages);

// Foreach key generate the page
foreach ($listOfKeys as $key) {
	$page = buildPage($key);
	echo $page->title();
	echo $page->permalink();
}

?>
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

Now if you want to get the pages with the type static, is more easy because returns all the static pages, and on published pages could be a lot of them so you need to filter by pagenumber.

Code: Select all

<?php

$listOfKeys = $dbPages->getStaticDB($onlyKeys=true);

foreach ($listOfKeys as $key) {
	$page = buildPage($key);
	echo $page->title();
	echo $page->permalink();
}

?>
jonathanholvey
Ssr. Bludit
Posts: 23
Joined: Mon May 22, 2017 10:15 pm

Thanks for that!
Post Reply