Jump to content

Getting page field's title


ferahl
 Share

Recommended Posts

Hi,

I am printing out some "post" page children on my home page. These "post" pages have a field called "category" which is a fixed list of pages - "News/Events/Projects".

My code looks like this:

$posts = $pages->find("parent=/posts/, limit=6"); 
foreach($posts as $post) {
 // render out
}

The field name is "category" but when I do $post->category it returns a page ID like 1014, if I do:

$pages->get($post->category)->title

This returns "Home" instead of the category which is one of "News/Events/Projects".

What am I doing wrong?

Thanks

Link to comment
Share on other sites

If it's a single page field

$post->category->title

If multiple, it's an array of pages

$post->category->first()->title

If think your example would have to be

$pages->get($post->category->id)->title

But no need to get the page as you already got it (or the bunch of them as pagearray)

  • Like 3
Link to comment
Share on other sites

If it's a single page field

$post->category->title

If multiple, it's an array of pages

$post->category->first()->title

If think your example would have to be

$pages->get($post->category->id)->title

But no need to get the page as you already got it (or the bunch of them as pagearray)

Damn pretty obvious! $post->category->first()->title worked thanks a lot!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...