Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering out categories in paginator.posts #2018

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

Filtering out categories in paginator.posts #2018

mdo opened this issue Feb 5, 2014 · 6 comments

Comments

@mdo
Copy link

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?

@doktorbro
Copy link
Member

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

@parkr
Copy link
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
Copy link
Author

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
Copy link

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
Copy link

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.

@djacquel
Copy link

Done jekyll/jekyll-paginate#6

@jekyll jekyll 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.
Projects
None yet
Development

No branches or pull requests

8 participants