# Separating the categories and sub-category

**URL:** <https://talk.jekyllrb.com/t/separating-the-categories-and-sub-category/966>\
**Category:** Help\
**Created:** [September 10, 2017, 7:57am UTC](https://talk.jekyllrb.com/t/separating-the-categories-and-sub-category/966 "2017-09-10T07:57:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashumittal](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/yashumittal/32/1260_2.png) [@yashumittal](https://talk.jekyllrb.com/u/yashumittal)\
**Post date:** [September 10, 2017, 7:57am UTC](https://talk.jekyllrb.com/t/separating-the-categories-and-sub-category/966/1 "2017-09-10T07:57:00Z")

</div>

How to separate the category.

![image](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/1X/9b100f6b63c6c84e42be296c401282fc1d228c9c.png)

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:

```auto
              {% 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 🕶)_

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [September 10, 2017, 3:15pm UTC](https://talk.jekyllrb.com/t/separating-the-categories-and-sub-category/966/2 "2017-09-10T15:15:34Z")

</div>

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:

```auto
{% 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/](http://ephotopros.com/categories/)

---

<div class="post-metadata">

**Author:** ![yashumittal](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/yashumittal/32/1260_2.png) [@yashumittal](https://talk.jekyllrb.com/u/yashumittal)\
**Post date:** [September 10, 2017, 5:46pm UTC](https://talk.jekyllrb.com/t/separating-the-categories-and-sub-category/966/3 "2017-09-10T17:46:49Z")

</div>

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

I have added

```auto
tags: product business idea

```

and the output is:

![image](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/1X/388fd1101c058eb8b1c780840c6f399d48cda05b.png)

how can I separate each tag?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 10, 2017, 5:57pm UTC](https://talk.jekyllrb.com/t/separating-the-categories-and-sub-category/966/4 "2017-09-10T17:57:49Z")

</div>

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

```auto
tags: [product, business, idea]

```

Or

```auto
tags: 
  - product 
  - business
  - idea

```
