Filtering out categories in paginator.posts #2018

Closed
mdo opened this Issue Feb 5, 2014 · 6 comments

Projects

None yet

8 participants

@mdo
mdo commented Feb 5, 2014

Currently there doesn't seem to be a way to filter out any post that is in a category. I'm trying to have a separate list of posts that doesn't affect the main posts index in the slightest, but it seems there is no way to do it.

I can get close with this:

{% for post in paginator.posts %}
  {% unless post.categories contains 'resources' %}
  <div class="entry">
    <a class="entry-thumb" href="{{ post.source }}" title="Visit {{ post.title }}">
      {{ post.content }}
      <span class="icon icon-forward entry-icon"></span>
    </a>
    <div class="entry-content">
      <h2 class="entry-title">
        <a href="{{ post.url }}">{{ post.title }}</a>
      </h2>
      <p class="entry-date">{{ post.date | date: "%B %-d %Y" }}</p>
    </div>
  </div>
  {% endunless %}
{% endfor %}

The goal of that code is to get a list of posts (config says 10 posts per page), but don't include any of the posts that are in the resources category. However, it falls short in that it will find 10 posts, then filter out the ones in the resources category, leaving me with fewer than 10 posts on the generated page.

What I'd love to be able to do is one of two things:

  1. Have a default category so that I can generate a custom loop for showing posts.
  2. Have an option to filter out any and all categories in the default loop.

Is that too far out of left field for this? Does it makes sense what I'm trying to do?

@penibelst
Member

The where filter is coming in the next major version. (#1875)

@parkr
Member
parkr commented Feb 5, 2014

Hey @mdo! Thanks for filing the issue. 😃 Always love seeing your avatar 'round these parts.

Have a default category so that I can generate a custom loop for showing posts.

Could you clarify, please? What do you envision for this? site.filtered_posts? site.default_posts?

Have an option to filter out any and all categories in the default loop.

It sounds like you want the inverse of the where filter, something like an except filter. It would turn your loop into:

{% assign relevant = site.posts | except:"category","resources" %}
{% for post in relevant %}
  {{ post.whatever }}
{% endfor %}

The struggle here is pre-filtering the paginator set of posts – there's currently no way to do this. It's been requested before and I figure we should do it.

@parkr parkr added the Feature label Feb 5, 2014
@mdo
mdo commented Feb 5, 2014

site.default_posts sounds about right. I want to list out the posts that aren't in any category.

It sounds like you want the inverse of the where filter, something like an except filter.

That sounds and looks exactly like what I want :).

@macta
macta commented Feb 26, 2014

I too would love see to see this feature. I'm struggling to move from Joomla for this very reason.

I kind of expected the Paginator to just pick up posts in a single directory hierarchy (off the root) - so if I had /blog/_posts and /poems/_posts then the Paginator would process them independently. It sounds like the filtering above would be more flexible - and would allow this type of behavior.

@mhulse
mhulse commented Feb 26, 2014

I'd also like to see this feature.

I was recently trying to figure out how to get the "Next" and "Previous" page links (for the permalink pages ... i.e., the "full post" view) to skip posts.

For my silly blog, I've got some posts that are marked as "external", so when clicked, they go to the external website; when page between full story pages, I couldn't figure out a way to paginate between all posts except a specific category (or tag, or custom front matter key).

It would be rad to have the ability to say "paginate between X and ignore Y" without losing items, like stated in the first post here:

However, it falls short in that it will find 10 posts, then filter out the ones in the resources category, leaving me with fewer than 10 posts on the generated page.

Anyway, +1 from me. I just wish I had the über skill to contribute to this issue.

@parkr parkr added this to the 2.1 milestone Feb 26, 2014
@parkr parkr modified the milestone: 2.2, 2.1 Jun 16, 2014
@parkr parkr referenced this issue in jekyll/jekyll-paginate Jul 31, 2014
Closed

Allow to exclude certain categories from paginated posts #6

@parkr parkr closed this Jul 31, 2014
@jekyllbot jekyllbot locked and limited conversation to collaborators Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.