Is it possible to exclude posts with particular tags from an author's post index?

I’m putting together a publication for a colleague who has been published on many external websites. Along with including the regular posts of this colleague in the regular blog feed, I’ve also integrated the following code into the routes.yaml file

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: tags:-[hash-external]
    data:
        external:
            resource: posts
            type: browse
            filter: tags:[hash-external]
            limit: 3
  /external/:
    permalink: /404/
    template: index
    filter: tags:[hash-external]
    controller: channel

so that in the footer I can display the title and feature image of a few of those posts, both of which link to those articles on the external sites via usage of the Canonical URL helper:

{{#has tag='#external' }}
<a href='{{ canonical_url }}' target ='_blank'>{{ title }}</a>
{{else}}
<a href='{{ url }}'>{{ title }}</a>
{{/has}}

I currently have two staff accounts (for the same author) set up for these internal and #external posts, the reader thus being able to visit either .../author/author-name or .../author/author-name-external-posts to see a listing of those two separate accounts.

What I’d like to do though is combine the two author accounts into one. I figure I can pull it off with some custom page work, but the only issue I envision is the post count (which the theme I’m using utilizes). That is, while I think I’ll be able to separate the internal and #external posts on two different pages, they’ll both display the cumulative total of posts: instead of displaying, say “200 posts” and “100 posts”, they’ll both display “300 posts”.

Long story short, might there be a way to exclude the #external tag from {{plural ../pagination.total}} in the same way that I’ve done for the Canonical URL above?

I’ve read this through several times and I can’t quite grasp what it is you’re having a problem with. Everything you’ve said sounds totally within the realms of possibility!

the only issue I envision is the post count (which the theme I’m using utilizes). That is, while I think I’ll be able to separate the internal and #external posts on two different pages, they’ll both display the cumulative total of posts: instead of displaying, say “200 posts” and “100 posts”, they’ll both display “300 posts”.

You’ve already setup 2 collections, one with the internal posts and one with the external posts. The “index” pages for each collection should output the correct post count, because each collection only knows about the posts inside it.

Unless you’re talking about what’s output on the author/x pages?

Can you maybe show the full code for the template that isn’t outputting the correct pagination.total?

1 Like

Yeah, you’re not the only one who’s confused, sorry about that :grimacing: Cause not only did I not understand that code up above well enough when I started this thread (and still kinda don’t – the routes.yaml stuff wasn’t written by me), but I now see that I was looking at the wrong issue and was thus explaining things incorrectly.

Yes, sorry, it’s the author/x page that I’m talking about (at least you understand what I’m talking about :stuck_out_tongue_winking_eye:).

First off, and having combined all the internal and #external posts under one staff member, you can see above that the /external collection has been set up to display posts tagged #external. It works (mostly) great. However, what I’ve been unable to figure out on the other end is how to exclude posts with the tag #external from this author’s page, /author/x.

I’ve conversed with the developer of the theme I’m using for this, and he suggested that the solution might be to create a custom template for the author, while utilizing something like this:

{{#get 'posts' filter='author:allan+tag:-podcast' as |posts|}}
{{> loop }}
{{/get}}

I unfortunately couldn’t get things to work, and what I’m wondering is whether or not this is possible – which I figure will simultaneously solve the issue of displaying the correct pagination sum that I somewhat cryptically alluded to up above.

As requested, this is the relevant code used in the author.hbs file, which is effectively “the full code for the template that isn’t outputting the correct pagination.total”.

{{!< default}}

<div class='o-wrapper'>

  <div class='o-grid'>
    <div class='o-grid__col o-grid__col--full'>
      {{#author}}
        <div class='c-author'>
          {{#if profile_image}}
            <div class='c-author__media'>
              <img src='{{ profile_image }}' alt='{{ name }}' class='c-author__image'>
            </div>
          {{/if}}

          <div class='c-author__content'>
            <h2 class='c-author__title'>{{ name }}</h2>
            {{#if bio}}
              <p class='c-author__bio'>{{ bio }}</p>
            {{/if}}
          </div>

          <div class='c-author__links'>
            <ul class='o-plain-list'>
              <li class='c-author__links-item' aria-label='Posts'>
                <span class='c-author__links-icon'>{{> SVGs/article}}</span>
                {{plural ../pagination.total empty='No posts' singular='% post' plural='% posts'}}
              </li>
            </ul>
          </div>
        </div>
      {{/author}}
    </div>
  </div>

  <div class='o-grid js-grid'>
    {{> loop }}
  </div>

</div>

I’m guessing then that if it were in fact possible to exclude those #external posts from that staff member’s page that the pagination total displayed would also be correct :crossed_fingers:

EDIT: Would it be appropriate/beneficial to change the title of this thread to “Is it possible to exclude posts with particular tags from an author’s page?”?