Multi Neighbors plugin for Pelican
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.rst
__init__.py
multi_neighbors.py
test_multi_neighbors.py

README.rst

Multi Neighbors Plugin for Pelican

This Pelican plugin adds the next_articles (a list of newer articles) and prev_articles (a list of older articles) variables to every article's context.

Usage

To install this plugin, see How to use plugins from the Pelican documentation.

By default, up to 5 neighbors are listed in each direction. You may customize this value by defining MULTI_NEIGHBORS in your settings file, e.g.:

MULTI_NEIGHBORS = 3

The code to output the variables in your article template might look like the following:

{% if article.prev_articles %}
    <nav class="older">
        <h1>Previous articles</h1>
        <ul>
            {% for article in article.prev_articles %}
                <li>
                    <a href="{{ SITEURL }}/{{ article.url }}">
                        {{ article.title }}
                    </a>
                </li>
            {% endfor %}
        </ul>
    </nav>
{% endif %}
{% if article.next_articles %}
    <nav class="newer">
        <h1>Next articles</h1>
        <ul>
            {% for article in article.next_articles %}
                <li>
                    <a href="{{ SITEURL }}/{{ article.url }}">
                        {{ article.title }}
                    </a>
                </li>
            {% endfor %}
        </ul>
    </nav>
{% endif %}