[Solved] List of posts for each category creates additional empty bullet

Hi all,
This is my first post here. I have the following code to display posts list in category wise. But I see additional bullet in the final HTML page.

{% for category in site.categories %}                               
{% for posts in category %}                                         
<ul>                                                                
{% for post in posts %}                                             
<li><a class="post-link" href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>                                                               
{% endfor %}                                                        
{% endfor %}

And it give the following output. Assuming I have only two categories.
.
. post1
. post4
.
. post3
. post2

I don’t know why an extra bullet is showing at the starting of post list for each category.

I think you have one to many for statements. I bet if you have 3 cats you will have 3 empty bullets.

I’d try it without the 3rd one, maybe like this (not tested):

<ul>      
{% for category in site.categories %}                           
{% for posts in category %}                                                                                                                                     
<li><a class="post-link" href="{{ posts.url }}">{{ posts.title }}</a></li>                                                         
{% endfor %}                                                        
{% endfor %}
</ul>     

I do it like this to get the cat name as an H2, a little different than you have but maybe it will help::


 
{% 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 %}

It leaves only empty bullets. No post titles or links… Like this…
.
.
.
.

try this:

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

category[1] contains all the post data, category[0] contains the category name I think. Not sure exactly what is contained in just category - I think it is a key:value pair and without specifying what you want - the key or the value - you get nothing?.

1 Like