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

Is there multi-category support? #160

Open
rampatra opened this issue Aug 8, 2020 · 4 comments
Open

Is there multi-category support? #160

rampatra opened this issue Aug 8, 2020 · 4 comments

Comments

@rampatra
Copy link

rampatra commented Aug 8, 2020

Can I list all posts on a page that belong to two categories, let's say, question and ruby? Right now I can list all posts either with category question or ruby but not both.

@ashmaroli
Copy link
Member

I think you can use Jekyll's where filter for this..
Disclaimer: The following is untested.

{% assign question_category_posts = ... %}
{% assign ruby_question_category_posts = question_category_posts | where: "categories", "ruby" %}

@rampatra
Copy link
Author

rampatra commented Aug 8, 2020

Actually, I want to create a generic page to show posts belonging to two categories.

For example,

  • If the URL is www.blog.com/category/question/ruby then show posts belonging to category question and ruby.
  • If the URL is www.blog.com/category/question/java then show posts belonging to category question and java.
  • If the URL is www.blog.com/category/scala then show posts belonging to category scala only.

Is this possible with jekyll-archives plugin or is there a better way?

@rampatra
Copy link
Author

rampatra commented Aug 8, 2020

If this feature isn't there in this plugin, it will be a good addition. We can add both and and or to combine different types.

@xulihang
Copy link

xulihang commented Dec 1, 2021

Hi there,

Here is a workaround I figured out:

  1. Combine categories to a path like question/java
 def categories
        categories = Hash.new
        @posts.each do |post|
          cats = post.data["categories"]
          cate = ""
          cats.each do |cat|
             cate = cate +"/"+ cat
          end 
          post_arr = categories.fetch(cate, [])
          post_arr.append(post)
          categories.store(cate, post_arr)
        end
        return categories
        # @site.categories
      end
  1. Modify slugify_string_title to do the slugifying by ourselves so that / will not be replaced with -.
      def slugify_string_title
        return unless title.is_a?(String)

        Utils.slugify(title, :mode => @config["slug_mode"]) # handle this
      end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants