prry

Hashtags in Pure Blog Feeds

I spent a little time this morning getting Pure Blog categories to automatically inject into the bottom of the feed content, using a custom function, and an amend to the feeds template. I will no longer need to write this manually at the bottom of each post.

/content/functions.php
----------------------

<?php

function render_hashtag_links(array $tags): string
{
    $tags = array_values(array_filter(array_map('trim', $tags)));
    if (!$tags) {
        return '';
    }

    $links = [];
    foreach ($tags as $tag) {
        $slug = normalize_tag($tag);
        $links[] = '<category>' . e($tag) . '</category>';
    }

    return implode(', ', $links);
}

?>

This creates a similar function to the existing tag function, but only provides the hashtag text, no link. This loads alongside the default /functions.php file, and will persist beyond updates. I then inject this into category elements below the description element inside feed.php

/feed.php (bottom of <item> block)
----------------------------------

<item>
    ...
    <description><![CDATA[<?= $content ?>]]></description>
    <?php if (!empty($post['tags'])): ?>
        <?= render_hashtag_links($post['tags']) ?>
    <?php endif; ?>
</item>

In theory I should be able to map a custom route to a custom feed.php, but in reality Pure Blog seems to default the original feed.php anyway - so while the custom function will persist, I'll need to remember to make this insert after the <?= $content ?> to feed.php whenever an update overwrites that file.

Also in version 2.0 Kev has added tag autocomplete. Once I've been through and made all of my existing tags lower case, that is going to be a great help. 2.0 looks like a monster of an update I still need to digest, I have no idea where Kev fins the time 🙏❤️!

By on

indieweb, pureblog, changelog

Reply by email

⬅ The one before
🚴‍♂️ ⏰00:50:26 📏24.42km 🛫492m ❤️‍🔥163bpm 🪫205W 🧁 607Kcal

Up next ➡
🚴‍♂️ ⏰00:59:04 📏36.29km 🛫102m ❤️‍🔥154bpm 🪫199W 🧁 706Kcal

Website Comments