Filtering posts onto separate page?
I would like to know how to have a section in the blog containing posts independent of those on the home page. For example, I would like to create a page called 'News' on which to put posts that do not appear on the home page.
If you have a list of entries in your template like so:
{{#entries}}
...
{{/entries}}
You can filter them such that only posts without the tag 'News' appear using the following:
{{#entries}}
{{^tagged.news}}
...
{{/tagged.news}}
{{/entries}}
Answered 2 years ago ·
Edit answer
Thanks for this answer! I have one followup question. I used this to filter out a category called photography and it works well. Is there a way to show the entire post and not just the title on the menu page? If you look at https://mpmilestogo.site/tagged/photography you can see it working but the post content and image does not show by default. Since this category is random photos I share and write stories about, I would like the category to work like it does without filtering out the category from the home page.
Answered 2 years ago · Edit answerFor sure, in order to change how the /tagged/photography
page displays its entries, you'll want to:
- Open up your template's
tagged.html
file, and copy everything inside the{{#entries}}..{{/entries}}
block into two new views calledtagged-list.html
andtagged-photography.html
. - Replace the
{{#entries}}..{{/entries}}
block intagged.html
with the following:
{{#entries}}
{{#first}}
{{#tagged.photography}}
{{> tagged-photography}}
{{/tagged.photography}}
{{^tagged.photography}}
{{> tagged-list}}
{{/tagged.photography}}
{{/first}}
{{/entries}}
What the code above does is render the view tagged-list.html
unless the current tag is 'photography', in which case render the view tagged-photography.html
.
Now you have that in place, you can modify the view tagged-photography.html
as you like: consider replacing the link to the post with the post's content, e.g.
{{#entries}}
{{{html}}}
{{/entries}}
Please let me know if you have any questions about this – it's of course complicated!
Answered 2 years ago · Edit answerI just got around to doing this. Wonderful and just what I wanted to highlight some photos and stories on my blog. Now the images appear as I want. Thanks David! Much appreciated.
Answered 2 years ago · Edit answerJust one minor question David. Now the photography tag shows images how I want but can I have the main site navigation bar on the top still along with the images? Navigation could be tricky unless I can show the main navigation bar element on the top like regular pages do.
Answered 2 years ago · Edit answerDid you include the template code that renders the header/navigation, etc. in the file tagged-photography.html? The specific code required before the {{#entries}}
tag looks like this:
<!DOCTYPE html>
<html>
{{> head}}
<body>
{{> header}}
<div class="container">
<div class="main">
And after the {{/entries}}
tag like so:
</div>
</div>
{{> footer}}
</body>
</html>
Answered 2 years ago ·
Edit answer
I just went back and looked at the tagged-photography.html view and it appears correct but the site still renders without the top navigation bar. I went back and checked the previous work as well. On the photos tag page it shows the title of the post at the very top where the site navigation menu usually is. If I click on that, I go to home page of my blog. The rest of the nav bar menus or pages are not present.
Answered 2 years ago · Edit answerOk, please send us a link to your site and I'll look into the specifics of your implementation
Answered 2 years ago · Edit answerThanks David! You fixed it. I sent you some email letting you know but sometimes here in Cambodia, email gets kinda stuck. Now my photos page is exactly how I want it. Thanks for fixing and providing the superlative support.
Answered 2 years ago · Edit answerTo follow up on this I have two additional questions:
is it possible to exclude multiple tags from being displayed on the front page in an "either/or" way? Say I want to have a section of images of a trip to Bali and a separate one with images of a trip to Australia. I tried to use the "OR" syntax from php, so {{^tagged.bali} || {^tagged.australia}} but it isn't working. Is this possible and what would be the correct synthax?
Is it possible to exclude the most recent cat or dog image from the above, so it is actually rendered on the start page? That way I could update each section by simply dropping new images to the folders (or deleting some) and this update would automatically bubble up to the front page
Thank you
Answered a year ago · Edit answerYes, on both counts:
1. To exclude multiple tags, nest multiple filters, e.g.
{{^tagged.bali}}
{{^tagged.australia}}
Only rendered for posts without the tags 'bali' and 'australia'
{{/tagged.australia}}
{{/tagged.bali}}
2. Could you use the first
property of the first entry in the list of entries to accomplish this? e.g.
{{#entries}}
{{#first}}
Only rendered for the most recent post...
{{/first}}
{{/entries}}
{{#entries}}
{{^first}}
{{^tagged.bali}}
{{^tagged.australia}}
Only rendered for posts which are not the first post
and which are not tagged bali and australia.
{{/tagged.australia}}
{{/tagged.bali}}
{{/first}}
{{/entries}}
Does that help? Please let me know if you have any questions
Answered 10 months ago · Edit answer