Getting a list of posts in theme

Gravatar dfh

  • Posts: 3
  • Topic Created: Fri Jan 13 09:28:35 2012 +0100

Hi there!

I decided to use Chyrp for a small blog on a site that I'm making. Looks good so far but now I'm having a little problem.

I'm making my own layout, and I want to display a list of the, say, 20 latest posts in a sidebar on every page. My idea was to just put this code in the layouts/default.twig layout, but I don't understand how to get it to work.

What I did so far was to iterate the posts.paginated variable. This works on the index page, but not on pages for individual posts, on which the variable seems to be empty.

Any suggestions would be greatly appreciated, thanks!

Gravatar jack

have you seen http://chyrp.net/2011/11/20/how-to-use-twig/

Gravatar dfh

Yes. Did not help. Looping/printing is not a problem. What I don't know is how to get the actual posts.

Gravatar jack

whats your code? something like {% for post in posts.paginated %} {% include "feathers/" ~ post.feather ~ ".twig" %} {% else %} ${ "Nothing here yet!" | translate } {% endfor %}

Gravatar dfh

Yes. "What I did so far was to iterate the posts.paginated variable. This works on the index page, but not on pages for individual posts, on which the variable seems to be empty."

Gravatar jack

ahh, sorry. simple fix then. open root/includes/controllers/main.php line 419 in the beta. it should be this currently. array("post" => $post, "posts" => array($post)), add a line underneath "postlist" => new Paginator(Post::find(array("placeholders" => false)) then use the postlist.paginated variable to loop through.

Gravatar dfh

Alright, thank you!

Gravatar drahnr

Is there a fix for 2.5 beta 2 availiable? Putting the said line does not work. Any hints appreciated.

Gravatar jack

have you modified your theme too?

Gravatar drahnr

I did, but the page di not even render, just an error (cant recall by now)