Monday, April 27, 2009

Re: Showing last 5 posts in a blog

Assuming you have a "created" field:

$this->Post->find(
'all',
array(
'order' => array(
'Post.created' => 'DESC'
),
'limit' => 5
)
);

If you don't already have one, add it to your table as datetime
DEFAULT NULL and Cake will take care of inserting the value when you
save a new post.

On Mon, Apr 27, 2009 at 9:27 PM, mig_akira <mig_akira@hotmail.com> wrote:
>
>
> Hello everyone.
>
> I'm very new to cakephp.
>
> I would like to show in a page my last 5 blog posts. I made a function
> viewAll that shows all posts, but I don't know how can I show only the last
> 5 entries.
>
> Any help would be appreciated! Thanks!
> --
> View this message in context: http://www.nabble.com/Showing-last-5-posts-in-a-blog-tp23267920p23267920.html
> Sent from the CakePHP mailing list archive at Nabble.com.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: