-
|
I want to dynamically update the post count in the example text below when I preview and/or build the site. In the editor
Published website
The solution should be able to count the articles with a specific tag, and inject that number on preview/build. I've looked at the plugins below, but I'm not sure that either of them can do this, and I don't want to buy Publii's plugin unless I know that it can achieve what I want. Perhaps @bjazmoore can comment on his plugin? https://github.com/bjazmoore/Key-Replacement I've tried creating a custom helper, but that got me nowhere thus far. Right now, I'm looking at hard coding the whole thing by creating a custom template with all the text, but I'd really prefer to be able to edit all this within the application. By default, Publii shows a counter in superscript text on tag pages (see example below), so the functionality is already there, but I've yet to figure out how to use it for this specific purpose.
Example taken from https://demo.getpublii.eu/themes/mono/tags/three-dimensional/. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 13 replies
-
|
As I mentioned in the original comment, I have, for now, figured out and used the workaround of using a custom template. In that template, I've hard coded the first paragraph as shown below. The rest of the text is produced in the Publii editor and contained in the This is of course not optimal, as the text in the template is not shown in the editor, and it's much easier to edit the content in the editor. I'd very much prefer if I could just have a place holder text in the editor, which gets replaced with the current amount on build. I've tested Key-Replacement now as well, but that plugin could not solve this, as it just replaces text with text. If someone knows if this is possible with the Smart Replacer or in some other way, please chime in. <div class="content__entry">
<p>This website currently has {{#getTag 6}}{{postsNumber}}{{/getTag}} articles of this kind... some more text etc </p>
{{{text}}}
</div> |
Beta Was this translation helpful? Give feedback.
-
|
Rather than hardcoding the text, I would use the Post/Page Settings API so that your custom text can be entered per Post/page on the side:
This works if your text is meant to appear at the same place for every post, but with different text on each post. You could even add a setting to enable/disable it. Otherwise, I'm not super familiar with them, but a custom helper might be useful. I'll drop some links here for further reading: |
Beta Was this translation helpful? Give feedback.
-
|
Hello @Backspaze, I confirm that you can't achieve this with plugins because they operate on the HTML output — that is, after Handlebars (hbs) has already done its job — and from the HTML output you cannot retrieve the number of posts associated with a specific tag. The solution I recommend is the one proposed by @candidexmedia using the Post/Page Settings API. Essentially, you need to create a custom post option in the Then, in your custom post template ( |
Beta Was this translation helpful? Give feedback.
-
|
Hello, Thinking about it, there is the option of using a custom helper, which essentially works like a mini plugin. You can insert the
I had a little help from Gemini, but it should work :) |
Beta Was this translation helpful? Give feedback.
-
|
Hey, I built a small plugin that adds shortcodes for displaying content counts on your Publii site - posts, pages, tags, authors. What it doesDrop a shortcode like Basic shortcodes:
Tag & author shortcodes: You can also count posts per tag or author. Use either the slug or the ID:
Label - position controls the output order: The position of
Label before is good for headings and labels. Label after reads naturally in sentences: The separator for label-before ( Example in a Handlebars template: SettingsBy default, the plugin only counts visible (published) posts and pages. If you also want to include items marked as hidden in Publii, you can enable that in the plugin settings. There's also an option to wrap the output in Shortcodes in You can grab the plugin here: contentCounter_1.2.0.zip |
Beta Was this translation helpful? Give feedback.


Hey,
I built a small plugin that adds shortcodes for displaying content counts on your Publii site - posts, pages, tags, authors.
What it does
Drop a shortcode like
[pcc=posts]anywhere - in a post, a page, or directly in your theme's.hbstemplates - and it gets replaced with the actual number during rendering.Basic shortcodes:
[pcc=posts]- number of published posts[pcc=pages]- number of published pages[pcc=total]- combined total (posts + pages)[pcc=featured]- number of featured postsTag & author shortcodes:
You can also count posts per tag or author. Use either the slug or the ID:
[pcc=tag name=tutorials]- number of posts in a tag (by slug)[pcc=tag id=5]- same, but by tag ID