Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control the order of pages from within a pelican article category?

I am using pelican jinja2 templates in order to generate a navigation menu based on the category and I need a way to control the order of the pages, or at least a trick to allow me to choose the first page to be listed.

{% for a in articles %}
     {% if a.category == category %}
         <li><a href="{{ SITEURL }}/{{ a.slug }}">{{ a.title }}
     {% endif %}
{% endfor %}

How can a make one specific article page to be the first. Their sourse is in markdown format.

like image 276
sorin Avatar asked Aug 29 '13 20:08

sorin


2 Answers

Pelican 3.5 will introduce built-in support for article and page ordering. You can define in your pelicanconf.py by which metadata attribute articles and pages should be sorted. The two variables are:

ARTICLE_ORDER_BY = 'attribute'
PAGE_ORDER_BY = 'attribute'

For this to work correctly, you must ensure that:

  • every page / article defines the specified attribute, otherwise you will get a compiler error saying the page / article class doesn't have this attribute
  • your attribute always uses the same number of character; so the values 1, 10 and 100 won't produce a correct order, but 001, 010 and 100 will do

With that infrastructure in place, outputting articles in the correct order should work for your code without modifications.

like image 53
Sebi Avatar answered Oct 24 '22 11:10

Sebi


To workaround the problem, you can disable categories and pages from being displayed automatically and set the menuitems manually in the configuration:

DISPLAY_CATEGORIES_ON_MENU = False
DISPLAY_PAGES_ON_MENU = False

MENUITEMS = (
    ('Home', '/'),
    ('Archives', '/archives.html'),
    ('Tags', '/tags.html'),
    ('Category1', 'category/category1.html'),
    ('Category2', 'category/category2.html'),
)
like image 42
jcollado Avatar answered Oct 24 '22 11:10

jcollado