Readme.rst 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Neighbor Articles Plugin for Pelican
  2. ====================================
  3. This plugin adds ``next_article`` (newer) and ``prev_article`` (older)
  4. variables to the article's context.
  5. Also adds ``next_article_in_category`` and ``prev_article_in_category``.
  6. Usage
  7. -----
  8. .. code-block:: html+jinja
  9. <ul>
  10. {% if article.prev_article %}
  11. <li>
  12. <a href="{{ SITEURL }}/{{ article.prev_article.url}}">
  13. {{ article.prev_article.title }}
  14. </a>
  15. </li>
  16. {% endif %}
  17. {% if article.next_article %}
  18. <li>
  19. <a href="{{ SITEURL }}/{{ article.next_article.url}}">
  20. {{ article.next_article.title }}
  21. </a>
  22. </li>
  23. {% endif %}
  24. </ul>
  25. <ul>
  26. {% if article.prev_article_in_category %}
  27. <li>
  28. <a href="{{ SITEURL }}/{{ article.prev_article_in_category.url}}">
  29. {{ article.prev_article_in_category.title }}
  30. </a>
  31. </li>
  32. {% endif %}
  33. {% if article.next_article_in_category %}
  34. <li>
  35. <a href="{{ SITEURL }}/{{ article.next_article_in_category.url}}">
  36. {{ article.next_article_in_category.title }}
  37. </a>
  38. </li>
  39. {% endif %}
  40. </ul>
  41. Usage with the Subcategory plugin
  42. ---------------------------------
  43. If you want to get the neigbors within a subcategory it's a little different.
  44. Since an article can belong to more than one subcategory, subcategories are
  45. stored in a list. If you have an article with subcategories like
  46. ``Category/Foo/Bar``
  47. it will belong to both subcategory Foo, and Foo/Bar. Subcategory neighbors are
  48. added to an article as ``next_article_in_subcategory#`` and
  49. ``prev_article_in_subcategory#`` where ``#`` is the level of subcategory. So using
  50. the example from above, subcategory1 will be Foo, and subcategory2 Foo/Bar.
  51. Therefor the usage with subcategories is:
  52. .. code-block:: html+jinja
  53. <ul>
  54. {% if article.prev_article_in_subcategory1 %}
  55. <li>
  56. <a href="{{ SITEURL }}/{{ article.prev_article_in_subcategory1.url}}">
  57. {{ article.prev_article_in_subcategory1.title }}
  58. </a>
  59. </li>
  60. {% endif %}
  61. {% if article.next_article_in_subcategory1 %}
  62. <li>
  63. <a href="{{ SITEURL }}/{{ article.next_article_in_subcategory1.url}}">
  64. {{ article.next_article_in_subcategory1.title }}
  65. </a>
  66. </li>
  67. {% endif %}
  68. </ul>
  69. <ul>
  70. {% if article.prev_article_in_subcategory2 %}
  71. <li>
  72. <a href="{{ SITEURL }}/{{ article.prev_article_in_subcategory2.url}}">
  73. {{ article.prev_article_in_subcategory2.title }}
  74. </a>
  75. </li>
  76. {% endif %}
  77. {% if article.next_article_in_subcategory2 %}
  78. <li>
  79. <a href="{{ SITEURL }}/{{ article.next_article_in_subcategory2.url}}">
  80. {{ article.next_article_in_subcategory2.title }}
  81. </a>
  82. </li>
  83. {% endif %}
  84. </ul>