The title of the next and previous post

Post Reply
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Hi, I use to post links to the next and previous post:

Code: Select all

<?php echo Theme::siteUrl() . $page->previousKey(); ?>
<?php echo Theme::siteUrl() . $page->nextKey(); ?>
But how to deduce the title of the posts?
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Is there a solution to my problem? :oops:
hxii
Ssr. Bludit
Posts: 20
Joined: Sun Nov 22, 2015 11:01 am
Contact:

I guess you can use something like (after, obviously, writing the code more normally)

Code: Select all

$pre_page = $page->previousKey();
$next_page = $page->nextKey();

$page_handler = new Pages();
$pre_page_title = $page_handler->getPageDB($pre_page);
$next_page_title = $page_handler->getPageDB($next_page);
Learn by doing.

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

You can do something like this.

Code: Select all

$pageKey = $page->previousKey();
$page = buildPage($pageKey);
echo $page->title();
https://docs.bludit.com/en/dev-snippets/content-pages
User avatar
bayerberg
Master Bludit
Posts: 141
Joined: Wed Jun 07, 2017 1:05 pm
Location: London, UK
Has thanked: 7 times
Been thanked: 10 times
Contact:

this is a cool feature but needs a bit of tweaking. if you run a normal blog it works fine, but if you rely on categories and need to display next page in the category theres a need for a bit of code jiggery. would be great if this could be configurable in settings or with extra variable.
bludit plugins and themes - makeitblu | I do things, check them out on behance and dribbble.
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

I have a problem. The previous post is running, the next one shows the current post.

Code: Select all

<?php $prevPage = $page->previousKey();
$page = buildPage($prevPage);
echo ' <a href="' . $page->permalink() . '">' . $page->title() . '</a> '; ?>

<?php $nextPage = $page->nextKey();
$page = buildPage($nextPage);
echo ' <a href="' . $page->permalink() . '">' . $page->title() . '</a> '; ?>
Post Reply