randys.org

Wasting your precious bandwidth since 1999

Posts Tagged ‘templates’

Mephisto: How-to add monthly archives to the side-bar

One of the odd things I’m finding with Mephisto is that none of the templates I looked at had monthly archives in the sidebar. That’s generally not that strange, but Mephisto doesn’t really paginate (out of the box, anyway) sections (categories), so the lack of any way for a user (that would be you) to navigate to older posts is beyond me. So the search for some Liquid code to display monthly archives began.

Mephisto’s documentation is seriously lacking, but what can you expect from a small development team with no funding behind the app. Most of the links I followed were to the Mephisto Google Group. I took this snippet from one particular thread:

 <ul>
 {% for month in section.months %}
     {{ section | monthly_articles: month | assign_to: 'monthly_articles' }}
     <li>
     {% if monthly_articles %}
         {{ section | link_to_month: month }} ({{ monthly_articles | size }})
     {% else %}
         {{ month | format_date: 'my' }}
     {% endif %}
     </li>
 {% endfor %}
 </ul>

But this would still spit out months with no posts. We can’t have that! So, I turned it into this:

{% if section.months.size > 0 %}
<ul>
    <li class="head">Archives</li>
    {% for month in section.months %}
    {{ section | monthly_articles: month | assign_to: 'monthly_articles' }}
        {% if monthly_articles.size > 0 %}
            <li><span class="right">{{ monthly_articles | size }}</span>
            {{ section | link_to_month: month }} </li>
        {% endif %}
    {% endfor %}
</ul>
{% endif %}

Much better! Now I have this:

• • •

All content Copyright © Randy Sesser | Hosted by WebFaction
Entries (RSS) | Comments (RSS)