Can a post be "Pinned?"

Hello Forum,

Is there a way to “pin” a blog post to the top of your timeline, meaning that particular post is always shown as the most recent – first post on the blog? I am using the Arabica Theme.

Cheers!

{{- range first 1 (where .Site.Taxonomies.category.featured.Pages) }}
 <div class = "post-content e-content">
   {{ .Content }}
 </div>
{{- end }}

Something like that should work, with the post having a category of “featured”. You can then follow up with the normal index stuff. This will have the effect of showing that post twice (probably) if it’s the newest post. There’s certainly away around that, but not up for thinking through that at the moment.

2 Likes

Wow. Pinned posts per category would be very cool!

As @Moondeer is hinting, you can do this with an intersect between categories. intersect | Hugo

I see what you’re going for here, but it does seem a little overly complex, no? To show the top page that’s pinned you should just need something similar to what I have above:

{{- range first 1 (where .Site.Taxonomies.categories.personal-favorites.Pages) }}
<div class = "post-content e-content">
   {{ .Content }}
 </div>
{{- end }}

Would print the full post of the first page with a category of personal-favorites.

You could then list the remaining pages with:

{{ range after 1 (where .Site.Taxonomies.categories.personal-favorites.Pages)  }}
    {{ partial "post-list.html" . }}
{{ end }}

Or something similar.

If you wrap it in {{- range .Paginator.Pages }} ... {{- end }} in layouts/_default/taxonomy.html, you’ll already get just the pages in the category for the page you’re on.

Intersect and symdiff are good uses though, I see what you mean by having both. See what you’re trying, but I think it’s worth showing a slightly simpler method for others reading.

If your layouts/_default/taxonomy.html layout is something like this:

{{ $pinned = first 1 (intersect .Paginator.Pages .Site.Taxonomies.categories.personal-favorites.Pages) }}
{{- range $pinned.Pages }}
<div class = "post-content e-content">
  {{ .Content }}
 </div>
{{- end }}
{{- range  .Paginator.Pages | symdiff $pinned.Pages }}
  {{ partial "post-list.html" . }}
{{-end }}

What that says is “grab the first page only that is on the list of pages for this page (your category) that also has the category personal-favorites (make that whatever you want)”, then it says “iterate over that collection now called pinned and post the content of that post” (you can access other page variables things like .Title etc). Then once it’s done, it says "Go back and get every page that’s on the list for this page except the one that we just posted, and render the partial for that called “post-list” (you may have this setup differently).

1 Like

This is really exciting stuff. OK, caveat, I’m not a UX guy AT ALL, but I’ve been perusing the Hugo documentation and it occurred to me that a lot of things could be done by the user if you could include a Front Matter section in your post(s). The question is, when you publish a post on Micro.blog, if your post included Front Matter, will that be appended to the Front Matter that is generated by Micro.blog at post time? Hopefully this makes sense. If that is the current behavior, that seems likely to open a lot of customization doors… (?)

1 Like

Accessing/setting custom front matter is not currently supported on Micro.blog.

1 Like

I appreciate the work that others have done on this. I don’t know much about Micro.blog plugins, but could this be turned into a plugin at some point, for those of us who don’t have the same tinkering proficiency?

I would love to be able to pin posts, as well. A plugin seems like a good idea.

I think for this to be a plug-in, any theme that would load that plug in would need to support defining block from the plug in on their index layout. Otherwise, I think the plug in would have to replace the index page itself, which might be possible, but I can imagine doing so in a way that would work with all themes would be quite hard.

Thanks Jason. I’m not super concerned about it. More of a nice to have. At this point, I’m mostly hoping to get more stability and reliability on the platform. It has gotten to a nice level of features.