A simple approach to categories in Yellow

· 4 min ·

TL;DR:

Originally, I used the Author: setting in Yellow for categories, but it wasn't ideal. When seeking a way to integrate a microblog into my site, I considered using a second CMS. However, a simpler solution struck me: creating a Category: setting to filter and display articles chronologically on the start page with different layouts. I defined layouts for "blog," "image," and "micro" categories.

What's it about?

I had missed categories in Yellow some time ago and used the page setting Author: to help me. That wasn't ideal, of course, but it was enough at the time. Now I have a different approach, which somehow seems too simple to be true. But first things first.

My intention

I was looking for a way to integrate a kind of micro blog into my blog. Nothing dramatic, just a different formatting of the articles. In my head, it started with thinking about how I could integrate a second, simpler CMS into Yellow so that the articles would appear chronologically in a timeline. Then, as happens quickly with ADHD people, I spent a lot of time trying to find a suitable second CMS, while my brain continued to research alternatives to this approach in the back of my mind.

The spark

And suddenly this one thought came. At first it was only vague, but it became increasingly clear until it hit me with a certain force that made me grin: I simply give the articles another page setting Category:, according to which I can easily filter in blog-start.html via if ($page->get("Category") == "categoryName") and then give the different categories their individual layout on the start page.

It currently looks like this in my blog-start.html:

<?php if ($page->get("Category") == "blog") { ?>

<article class="<?php echo $page->getHtml("entryClass") ?>">
    <header>
        <h2><?php echo $page->getHtml("title") ?></h2>
        <p>
            <?php echo $page->getDateHtml("published") ?>            
            <?php echo " &middot; " . $page->parseContentShortcut("readingtime", "", "inline") . " min"; ?>
            <?php if ($page->isExisting("tag")): ?>
            <?php echo " &middot; Filed under: " ?>
            <?php $tagCounter = 0; foreach (preg_split("/\s*,\s*/", $page->get("tag")) as $tag) { if (++$tagCounter>1) echo ", "; echo "<a href=\"".$this->yellow->page->getLocation(true).$this->yellow->toolbox->normaliseArguments("tag:$tag")."\" class=\"tag\" title=\"Tag: ".htmlspecialchars($tag)."\" aria-label=\"Tag: ".htmlspecialchars($tag)."\">".htmlspecialchars($tag)."</a>"; } ?>
            <?php endif ?></p>
    </header>
    <p>
        <?php echo $this->yellow->toolbox->createTextDescription($page->getContentHtml(), 350, true, "<!--more-->", " ") ?>
    </p>
    <a class="entry-link" title="<?php echo $page->getHtml("title") ?>" aria-label="<?php echo $page->getHtml("title") ?>" href="<?php echo $page->getLocation(true) ?>"> </a>
</article>

<?php } elseif ($page->get("Category") == "image") { 
    $page->set("entryClass", "post-image") ?>
    <article class="<?php echo $page->getHtml("entryClass") ?>">
        <header>
            <h2><?php echo $page->getHtml("title") ?></h2>
            <p>
                <?php echo $page->getDateHtml("published") ?>            
                <?php echo " &middot; " . $page->parseContentShortcut("readingtime", "", "inline") . " min"; ?>
                <?php if ($page->isExisting("tag")): ?>
                <?php echo " &middot; Filed under: " ?>
                <?php $tagCounter = 0; foreach (preg_split("/\s*,\s*/", $page->get("tag")) as $tag) { if (++$tagCounter>1) echo ", "; echo "<a href=\"".$this->yellow->page->getLocation(true).$this->yellow->toolbox->normaliseArguments("tag:$tag")."\" class=\"tag\" title=\"Tag: ".htmlspecialchars($tag)."\" aria-label=\"Tag: ".htmlspecialchars($tag)."\">".htmlspecialchars($tag)."</a>"; } ?>
                <?php endif ?></p>
        </header>
        <p>
            <?php echo $page->getContentHtml() ?>
        </p>
        <a class="entry-link" title="<?php echo $page->getHtml("title") ?>" aria-label="<?php echo $page->getHtml("title") ?>" href="<?php echo $page->getLocation(true) ?>"> </a>
    </article>

<?php } elseif ($page->get("Category") == "micro") { 
    $page->set("entryClass", "post-micro") ?>
    <div class="<?php echo $page->getHtml("entryClass") ?>">
        <?php echo $page->getContentHtml() ?>

        <p class="entryMeta">
            <a title="Permalink to this post" aria-label="<?php echo $page->getHtml("title") ?>" href="<?php echo $page->getUrl(true) ?>">#</a> <?php echo $page->getDateHtml("published") ?>  
        </p>
    </div>
<?php } ?>

Firstly, there is my "blog" category. It is output as <article> with <header> and displays the content as an excerpt, limited to 350 characters. The "image " category differs from "blog " only in that it does not output an excerpt, but the unfiltered content of $page->getContentHtml, as I only post a photo with caption in this category. And, last but not least, the category "micro ". Articles with this category are not <article> and therefore have a completely different appearance. (As written here, I am still looking for a design for the micro posts and am open to all suggestions.)

Conclusion

That's it. It's often so easy to achieve what you want. It just seems important not to close your mind to alternatives and to give your brain space to come up with these alternatives.


Reply via e-mail

Back to top