How to get URL of latest post
-
- 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.
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.
Hi,
this is for the pages with the type published, you need to use getList because this type is paginated.
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();
}
?>
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();
}
?>