Skip to content

Instantly share code, notes, and snippets.

@pftnhr
Last active November 11, 2023 08:36
Show Gist options
  • Save pftnhr/42bf385adb6a907c4c6315a4bd7de742 to your computer and use it in GitHub Desktop.
Save pftnhr/42bf385adb6a907c4c6315a4bd7de742 to your computer and use it in GitHub Desktop.
[datenstrom-yellow] Lets you create a sticky post in a different design that is only on the blog homepage, and there at the top.

yellow-special1stpost

... lets you create a sticky post in a different design that is only on the blog homepage, and there at the top.

How it works

Save the blog-start.html in your system/layout folder and create a content/shared/special1stpost.md with the following content:

---
Title: Special 1st post
Layout: special1stpost
Tag: Example, Special 1st post
---

< Your content goes here. >
<!----------
Description: blog-start.html with modifications to check if there's a Special1stPost and if so, display it. Put this in the system/layout folder.
----------->
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<?php if ($this->yellow->page->get("blogWithFilter")): ?>
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php endif ?>
<?php // $pages = $this->yellow->page->getPages("blog")->paginate($this->yellow->system->get("blogPaginationLimit")) ?>
<?php // foreach ($pages as $page): ?>
<?php // $page->set("entryClass", "entry") ?>
<?php /* Replace the above three lines with these: */ ?>
<?php $pages = $this->yellow->page->getPages("blog"); ?>
<?php if ($this->yellow->page->isPage("special1stpost")) { ?>
<?php $pages->prepend($this->yellow->page->getPage("special1stpost")); ?>
<?php } ?>
<?php $pages->paginate($this->yellow->system->get("BlogPaginationLimit")); ?>
<?php foreach ($pages as $page): ?>
<?php if ($page->get("Layout") == "special1stpost") { ?>
<?php $page->set("entryClass", "special1stpost rounded") ?>
<?php } else { ?>
<?php $page->set("entryClass", "entry") ?>
<?php } ?>
<?php if ($page->isExisting("tag")): ?>
<?php foreach (preg_split("/\s*,\s*/", $page->get("tag")) as $tag) { $page->set("entryClass", $page->get("entryClass")." tag-".$this->yellow->lookup->normaliseArguments($tag, false)); } ?>
<?php endif ?>
<div class="<?php echo $page->getHtml("entryClass") ?>">
<div class="entry-title"><h1><a href="<?php echo $page->getLocation(true) ?>"><?php echo $page->getHtml("title") ?></a></h1></div>
<div class="entry-meta"><p><?php echo $page->getDateHtml("published") ?> <?php echo $this->yellow->language->getTextHtml("blogBy") ?> <?php $authorCounter = 0; foreach (preg_split("/\s*,\s*/", $page->get("author")) as $author) { if (++$authorCounter>1) echo ", "; echo "<a href=\"".$this->yellow->page->getLocation(true).$this->yellow->lookup->normaliseArguments("author:$author")."\">".htmlspecialchars($author)."</a>"; } ?></p></div>
<div class="entry-content"><?php echo $this->yellow->toolbox->createTextDescription($page->getContentHtml(), 0, false, "<!--more-->", "<a href=\"".$page->getLocation(true)."\">".$this->yellow->language->getTextHtml("blogMore")."</a>") ?></div>
</div>
<?php endforeach ?>
<?php $this->yellow->layout("pagination", $pages) ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
/*
Put this in the system/extensions folder
*/
.special1stpost {
padding: 0.25em 0.75rem 0.75em;
background-color: var(--link);
color: var(--bg);
font-weight: 500;
}
.special1stpost .entry-meta a,
.special1stpost .entry-content a {
color: var(--bg);
text-decoration: underline;
}
.special1stpost .entry-content p {
margin: 0;
}
.special1stpost .entry-title h1 {
margin: 0;
}
.special1stpost .entry-title h1 a,
.special1stpost .entry-title h1 a:hover {
color: var(--bg);
}
<?php
//
// Put this in the system/extensions folder
//
?>
<?php
class YellowSpecial1stpost {
const VERSION = "0.8.17";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle page extra data
public function onParsePageExtra($page, $name) {
$output = null;
if ($name=="header") {
$extensionLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreExtensionLocation");
$output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$extensionLocation}special1stpost.css\" />\n";
}
return $output;
}
}
@RonXTCdaBass
Copy link

RonXTCdaBass commented Nov 11, 2023

really nice!!
do you need an "extension.ini" file to make and publish this as addon?

 # Datenstrom Yellow extension

Extension: yellow-special1stpost
Version: 0.8.18
Description: Lets you create a sticky post that is only on the blog homepage, and there at the top. different design possible.
DocumentationUrl: https://gist.github.com/pftnhr/42bf385adb6a907c4c6315a4bd7de742
DownloadUrl: https://gist.github.com/pftnhr/42bf385adb6a907c4c6315a4bd7de742/archive/c59a9fd77a21a6489766d7a7473e57b4b7c4ece3.zip
Published: 2023-11-11 04:44:44
Developer: pftnhr, *.ini by RonXTCdaBass
Tag: feature, blog, sticky post
Status: experimental
system/extensions/special1stpost.php: special1stpost.php, create, update
system/extensions/special1stpost.css: special1stpost.css, create, update
content/shared/special1stpost.md: special1stpost.md, create, optional
system/layouts/blog-start.html: blog-start.html, create, update

i´ve tested at my yellow install.

my_sticky1post_screen

(anmerkung- ich musste die .php wieder löschen, sonst gab es probleme bei neuem BlogEintrag aber die css Teile kann ich ja in meine css einfügen...)

@pftnhr
Copy link
Author

pftnhr commented Nov 11, 2023

really nice!!
do you need an "extension.ini" file to make and publish this as addon?

Thank you for your effort, but this is not yet ready to become an extension. That's why I've put it here as a gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment