Can I show links to previous/next entry? #137
-
I'm missing the navigation from (previous) entry to (next) entry for the blog. It's christmas, maybe my wish could be fullfilled? ;) |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
Yes, it can be done with some Yellow customisation and the API. Here's an example plugin code <?php
// Copyright (c) 2013-2015 Datenstrom, http://datenstrom.se
// This file may be used and distributed under the terms of the public license.
// Blog plugin
class YellowBlogextension
{
const Version = "0.6.1";
var $yellow; //access to API
// Handle initialisation
function onLoad($yellow)
{
$this->yellow = $yellow;
}
// Handle page content parsing of custom block
function onParseContentBlock($page, $name, $text, $shortcut)
{
$output = NULL;
if($name=="bloglinks" && $shortcut)
{
list($location) = $this->yellow->toolbox->getTextArgs($text);
if(empty($location)) $location = $this->yellow->config->get("blogLocation");
$blog = $this->yellow->pages->find($location);
$pages = $blog ? $blog->getChildren(!$blog->isVisible()) : $this->yellow->pages->clean();
$pages->filter("template", "blog");
$page->setLastModified($pages->getModified());
if(count($pages))
{
$pageNumber = -1;
$pageLocation = $page->getLocation();
foreach($pages as $key=>$value) if($pageLocation == $value->getLocation()) { $pageNumber = $key; break; }
if($pageNumber > 0) $pagePrevious = $pages[$pageNumber-1];
if($pageNumber < count($pages)-1) $pageNext = $pages[$pageNumber+1];
$output = "<div class=\"".htmlspecialchars($name)."\">\n";
if($pageNext)
{
$output .= "<a class=\"next\" href=\"".$pageNext->getLocation()."\">← ".$pageNext->getHtml("titleNavigation")."</a>\n";
}
if($pagePrevious)
{
$output .= "<a class=\"previous\" href=\"".$pagePrevious->getLocation()."\">".$pagePrevious->getHtml("titleNavigation")." →</a>\n";
}
$output .= "</div>\n";
} else {
$page->error(500, "Bloglinks '$location' does not exist!");
}
}
return $output;
}
// Handle page extra HTML data
function onExtra($name)
{
return $this->onParseContentBlock($this->yellow->page, $name, "", true);
}
}
$yellow->plugins->register("blogextension", "YellowBlogextension", YellowBlogextension::Version);
?> Here's an example snippet <div class="content main">
...
<?php echo $yellow->page->getExtra("bloglinks") ?>
<?php echo $yellow->page->getExtra("comments") ?>
</div> This will add links to the bottom of each blog page. You can change the look with CSS, at the moment the code will only output the necessary HTML code. It's an example code, please feel free to modify and adjust it to your website. Hope this helps, happy coding. 😄 |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your work! Its funny: putting Using the shortcut Any idea? I copied the newest core.php - no changing. Tried it on another intstallation - same message. greets & thanks |
Beta Was this translation helpful? Give feedback.
-
Sorry about that, but there should be an easy fix. The function Does that work? |
Beta Was this translation helpful? Give feedback.
-
YESS! thats it! you are great, thanks a lot for fullfilling my wish so very fast! tnxtnxtnx! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Good to hear that it works. We can add something like this to the blog plugin later, if many people use it. Feel free to close the issue when it works for you. |
Beta Was this translation helpful? Give feedback.
-
Now there's an official plugin: https://github.com/datenstrom/yellow-plugins/tree/master/links |
Beta Was this translation helpful? Give feedback.
Now there's an official plugin: https://github.com/datenstrom/yellow-plugins/tree/master/links