Multiple lists of posts by section on the front page

63 views
Skip to first unread message

Paul Teehan

unread,
Oct 18, 2016, 12:24:33 PM10/18/16
to nikola-discuss
Hello,

I have 3 sections of posts and on the front page of my site I would like to display the most recent n posts (maybe n=5) from each section.
e.g.:

Section Foo
2016-10-14  Title ...
2016-10-15  Title 2 ...

Section Bar
2016-10-13  Title 3 ...

etc

I've got the front page displaying one list of all posts.  I don't really understand what controls the layout of the front page - I guess it gets a list of all posts and displays them using index.tmpl?   I thought about trying to filter by section (e.g. if post.section() =="Foo") but apparently posts don't have a section attribute.   My best guess is I need to do something special to get a custom template for the front page, and do something else to get a list of posts for each section?  I'm over my head at this point.

Many thanks
Paul

Chris Warrick

unread,
Oct 18, 2016, 2:16:55 PM10/18/16
to Nikola—Discuss
That’s not doable with index.tmpl. You could, however, disable/move
those indexes (via conf.py) and create a page using reStructuredText
and post lists:

https://getnikola.com/handbook.html#post-list

You could have a page that will end up as /index.html (2nd element in
PAGES = ""; slug = index) and put a post list for every section there.
index.tmpl (and general post indexes) already does some filtering and
stuff and is not feasible for your idea.

PS. you were looking for post.section_name()

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Paul Teehan

unread,
Oct 20, 2016, 4:23:47 AM10/20/16
to nikola-discuss
Thanks for the quick reply.  I didn't understand what you could do with reStructuredText, that is what I was looking for.

Nikola is fantastic, thank you :)

Dave

unread,
Nov 6, 2016, 10:26:31 AM11/6/16
to nikola-discuss
I didn't know about post-lists, they look really useful. I ended up writing lots of custom plugins for menus. archive, category, similar posts, section, popular tags. Seems I can replace a few of those now

Warut Phothiphan

unread,
Jul 4, 2017, 3:14:49 AM7/4/17
to nikola-discuss
I think this is similar to what I want to do. But how to disable the indexes in conf.py? And how to make the new page to be a front page? As the new page is .rst, how to make it end up as /index.html?

Thank you

Chris Warrick

unread,
Jul 4, 2017, 3:37:15 AM7/4/17
to Nikola—Discuss
On 4 July 2017 at 09:14, Warut Phothiphan <gto...@gmail.com> wrote:
> I think this is similar to what I want to do. But how to disable the indexes
> in conf.py? And how to make the new page to be a front page? As the new page
> is .rst, how to make it end up as /index.html?
>
> Thank you

We’ve got a tutorial for that:
https://getnikola.com/creating-a-site-not-a-blog-with-nikola.html

.rst and all other formats (except .php) always generate .html files.
If slug == index, pretty URLs are not used for that page.

Warut Phothiphan

unread,
Jul 4, 2017, 4:23:29 AM7/4/17
to nikola-discuss
Bingo!!    I just follow the tutorial and I achieve what I want. I was digging too deep into theme, template, plugin stuff  to modify the website generated from Getting Started tutorial to add my own front page. I think a lot of beginner did the same thing. Yes, I want to have a blog with my own front page. The easiest way to go is generating a new one following the tutorial Creating a Site (Not a Blog) with Nikola

Thank you
I love nikola.
Reply all
Reply to author
Forward
0 new messages