Separating the categories and sub-category


#1

How to separate the category.

image

In this image ruby on rails is the sub-category of Code. But still when I have written {{ page.category }}.

OUTPUT

CODERUBY-ON-RAILS

I want only ruby on rails show be shown.

I have tried to use this:

              {%  if page.categories contains 'tips' %}
                <a href="/category/business/tips">tips</a>
              {% else %}
                <a href="/category/business">business</a>
              {% endif %}

But is not very useful/productive, then I have to write the same code for every category and sub-category. (Because I prefer to use DRY :sunglasses:)


#2

jekyll doesn’t know what a sub category is. Are you saying that for that post there are 2 categories?

You could try to use tags - the category could be Code, the tag could be Ruby. You could also just make up your own front matter - on one of my sites I have articles, videos and downloads, so I made a custom front matter tag called Type where I can separate out by each of those without having to use category.

What are you trying to do? make a page that lists all your categories?

Here is a list of all content on one of my sites, broken down by category:

{% assign sorted_cats = site.categories | sort %}
{% for category in sorted_cats %}
{% assign sorted_posts = category[1] | reversed %}

  <h2 id="{{category[0] | uri_escape | downcase }}">{{ category[0] | capitalize }}</H2>
     <p>
      {% for p in sorted_posts %}
     <a href="/{{p.type | downcase}}/"><img src="/assets/img/{{p.type |downcase }}.png" alt="{{p.type}}" title="{{p.type}}"/></a> <a href="{{ p.url }}">{{ p.title }}</a> ({{p.type}}/{{p.category}}) &raquo;  <span class="entry-date"><time datetime="{{ p.date | date_to_xmlschema }}" itemprop="datePublished">{{ p.date | date: "%B %d, %Y" }}</time></span>
     <br />
      {% endfor %} 
    </p>
  
{% endfor %}

which is this page:
http://ephotopros.com/categories/


#3

I have tried adding tags. But still facing the same problem.

I have added

tags: product business idea

and the output is:

image

how can I separate each tag?


#4

You need to use commas so they’re treated as an array.

tags: [product, business, idea]

Or

tags: 
  - product 
  - business
  - idea