Your sites Log in Sign up Menu

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.


3 months ago, 12 replies   developers   tags   Improve this question

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 a year ago · Improve this 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 a year ago · Improve this answer

For sure, in order to change how the /tagged/photography page displays its entries, you'll want to:

  1. Open up your template's tagged.html file, and copy everything inside the {{#entries}}..{{/entries}} block into two new views called tagged-list.html and tagged-photography.html.
  2. Replace the {{#entries}}..{{/entries}} block in tagged.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 a year ago · Improve this answer

I 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 a year ago · Improve this answer

Just 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 a year ago · Improve this answer

Did 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 a year ago · Improve this 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 a year ago · Improve this answer

Ok, please send us a link to your site and I'll look into the specifics of your implementation

Answered a year ago · Improve this answer

Thanks 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 a year ago · Improve this answer

That's clever solution using the tag page.

Ray

Answered a year ago · Improve this answer

To follow up on this I have two additional questions:

1) 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?

2) 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 3 months ago · Improve this answer

Yes, 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 3 months ago · Improve this answer

Privacy Terms