How to List all the posts on your site by category

It’s common to show a list of posts arranged by categories on your homepage so that your customers can easily see all of your posts in different topics. It is essential for you to read carefully this instructional writing on How to list all posts on your site by category if you want to make this list on your own page.

How to list all posts on your site by category

Step 1: How to create a layout

Before taking an official step on adding the code to list your posts in category on your site, you need to know How to create a layout that will show the posts.

In _layouts directory, create a new file called home.html and add the following logic:


---
layout: default
---

{{ content }}
<ul class="myposts">
{% for post in site.posts %}
    <li><a href="{{ post.url }}">{{ post.title}}</a>
    <span class="postDate">{{ post.date | date: "%b %-d, %Y" }}</span>
    </li>
{% endfor %}
</ul>

Step 2: Create blog.md

Then, in your root directory, create a file called blog.md and specify the home layout:

---
title: Blog
layout: home
---

From that, contents of blog.md will be pushed into the `<p>It’s common to display a list of posts on your homepage so that your customers can easily catch sight of all of your posts in different topics. If you want to make this list on your own page, you have to read carefully this instructional writing on How to list all posts with the full content to get more information.</p>

How to list all posts with full content

Step 1: How to create a layout

Before taking an official step on adding the code to list your posts on your site with full content, you need to know How to create a layout that will display the posts.

In _layouts directory, create a new file called home.html and add the following logic:


---
layout: default
---

{{ content }}
<ul class="myposts">
{% for post in site.posts %}
    <li><a href="{{ post.url }}">{{ post.title}}</a>
    <span class="postDate">{{ post.date | date: "%b %-d, %Y" }}</span>
    </li>
{% endfor %}
</ul>

Step 2: Create blog.md

Then, in your root directory, create a file called blog.md and specify the home layout:

---
title: Blog
layout: home
---

From that, contents of blog.md will be pushed into the {{ content }} tag in the home layout which will be pushed into the {{ content }} tag of the default layout.

Step 3: Generate post list

Now, just embark on creating the code to make your posts appear right on your page with full content of each post.

site.posts directory contains all of the posts and helps you show them on your own homepage. Therefore, it is basically a matter of iterating over it. If you want to show the entire content of this post, you have to add exactly the following code:


...
{% for post in site.posts %}
  <article>
    <h2>
      <a href="{{ post.url }}">
        {{ post.title }}
      </a>
    </h2>
    <time datetime="{{ post.date | date: "%Y-%m-%d" }}">{{ post.date | date_to_long_string }}</time>
    {{ post.content }}
  </article>
{% endfor %}
...

Your setting process is completed and it is ready for your customers to see all your posts with full content.

Conclusion

It is much easier for your customers when they can see all of your posts with their full content right on your website. These posts are put in a default layout so that customers can be able to find them in a simple way. With some very basic steps above, we hope that this post brings useful information in your web development process. Do not forget to keep following us in next informative tutorials. Thank you for reading!

tag in the home layout which will be pushed into the <p>It’s common to display a list of posts on your homepage so that your customers can easily catch sight of all of your posts in different topics. If you want to make this list on your own page, you have to read carefully this instructional writing on How to list all posts with the full content to get more information.</p>

How to list all posts with full content

Step 1: How to create a layout

Before taking an official step on adding the code to list your posts on your site with full content, you need to know How to create a layout that will display the posts.

In _layouts directory, create a new file called home.html and add the following logic:


---
layout: default
---

{{ content }}
<ul class="myposts">
{% for post in site.posts %}
    <li><a href="{{ post.url }}">{{ post.title}}</a>
    <span class="postDate">{{ post.date | date: "%b %-d, %Y" }}</span>
    </li>
{% endfor %}
</ul>

Step 2: Create blog.md

Then, in your root directory, create a file called blog.md and specify the home layout:

---
title: Blog
layout: home
---

From that, contents of blog.md will be pushed into the {{ content }} tag in the home layout which will be pushed into the {{ content }} tag of the default layout.

Step 3: Generate post list

Now, just embark on creating the code to make your posts appear right on your page with full content of each post.

site.posts directory contains all of the posts and helps you show them on your own homepage. Therefore, it is basically a matter of iterating over it. If you want to show the entire content of this post, you have to add exactly the following code:


...
{% for post in site.posts %}
  <article>
    <h2>
      <a href="{{ post.url }}">
        {{ post.title }}
      </a>
    </h2>
    <time datetime="{{ post.date | date: "%Y-%m-%d" }}">{{ post.date | date_to_long_string }}</time>
    {{ post.content }}
  </article>
{% endfor %}
...

Your setting process is completed and it is ready for your customers to see all your posts with full content.

Conclusion

It is much easier for your customers when they can see all of your posts with their full content right on your website. These posts are put in a default layout so that customers can be able to find them in a simple way. With some very basic steps above, we hope that this post brings useful information in your web development process. Do not forget to keep following us in next informative tutorials. Thank you for reading!

tag of the default` layout.

Step 3: Generate post list

Now, take a step on adding the code to create a list of posts in category on your website.

If site.post directory helps you show all your posts, site.categories file will allow you arrange your posts in categories on your page. In this file, each item is an array with two elements. The first element in the array is the category name, the second element is a list of the posts in that category. Take a look at this following code and add it to your file.


...
{% for category in site.categories %}
  <h2>{{ category[0] }}</h2>
  <ul>
    {% for post in category[1] %}
      <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endfor %}
  </ul>
{% endfor %}
...

Your installation process is completed and your customers can see all your posts in categories from now.

Conclusion

It is extremely simpler for your customers to see all of your posts right on your website, especially in each category. With some very basic steps above, we hope that this post brings useful information in your web development process. Keep following us in next informative tutorials to get interesting things. Thank you for reading!