Jump to content

Finding the latest page in a category


Robguy
 Share

Recommended Posts

Hey guys,

So First Structure:

Home [template=home]

--Category [template=collection_list]

---SubCategory [template=collection_category]

----Articles [template=collection_basic]

Each 'Articles' has a field called 'thumbnail' and 'banner'.

I want to grab the latest article under a category and output the thumbnail and the banner.

I'm quite new to PW (loving it so far) and I'm hoping you guys will be able to support me here..

I know it needs to look something like this...

var_dump($pages->find("template=collection_basic, limit=1, sort=id")->thumbnail);

... Yes that's my var_dump but it's returning an error so.

Would appreciate any help!

Edited by Robguy
Link to comment
Share on other sites

Even though you're using "limit=1" the find() method should still return a PageArray. So you need to use "first()" on it before getting the thumbnail field. Alternatively use get() to only get the first item, which wouldn't need the "limit=1" selector. Also sorting by id might work, but actually "modified" or "created" are more descriptive. 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...