Would it be possible to use your next / previous templating on posts to only show the next or previous post for a specific tag?
Blot doesn't have an elegant way to do this right now, however you can accomplish this in an extremely inelegant way using the following technique:
<div id="posts-tagged-apple" style="display:none">
{{#all_entries}}
{{#tagged.apple}}
<a href="{{{url}}}">{{title}}</a>
{{/tagged.apple}}
{{/all_entries}}
</div>
<div id="next-with-tag"></div>
<div id="previous-with-tag"></div>
<script type="text/javascript">
var next;
var previous;
var links = document.querySelectorAll('#posts-tagged-apple a');
var nextContainer = document.getElementById('next-with-tag');
var previousContainer = document.getElementById('previous-with-tag');
links.forEach(function(node, index){
if (node.href !== "{{{entry.url}}}") return;
nextLink = links[index + 1];
previousLink = links[index - 1];
});
if (nextLink) nextContainer.append(nextLink);
if (previousLink) previousContainer.append(previous);
</script>
Please let me know if you have any questions about this or anything else. Note I haven't tested the code above so you may run into errors โ I'd be happy to debug if you send me a live link to your implementation.
Answered a year ago ยท Improve this answer