Jump to content

Noob question: Problem with page field used as link


manlio
 Share

Recommended Posts

Im' building for exercise pourpose a simple menu system based on pages.

Something like 

menu

-menu1

-menu2

-menu3

I have build a menu template with a page field that I would like to use in the href attributes of menu link.

Everything else works, but I don't know how to retrieve the url of the related page and not the ID.

foreach($menus as $menu) {
 echo $menu->title
 echo $menu->pagereference; //this return the ID of the related page, but I would like to get the url
?>
 
Something like this $menu->pagereference->url doesn't work so I don't know the syntax, I have tried different ways with no success.
Thank you and sorry for the silly question.
Regards
Link to comment
Share on other sites

Thank you adrian, unluckily this doesn't solve my problem.

I need only one page and before I setted up the field as  Single Page.

I try to put back to multiple and use your syntax but still I get this error:

Notice: Trying to get property of non-object in ...\site\templates\header.inc on line 

If I leave the field to Single Page and try to use 

 echo $menu->pagereference->url;

I get the same error.

Link to comment
Share on other sites

Thanks a lot to everybody! You all was really helpful. I think in one page I didn't set the pagereference and this cause the error (still not sure).

But now thanks to your advice works perfectly.

Great forum and PW rocks!

Edit:

Previously I setted the Page as "Single page (Page) or boolean false when none selected" instead of  "Single page (Page) or empty page (NullPage) when none selected" and now works also if a page reference is blank

  • Like 1
Link to comment
Share on other sites

If you'd choose "Single page (Page) or empty page (NullPage) when none selected" in your pagereference field, then the error wouldn't happen.

However, maybe you should modify your snippet to check if there is a page selected before outputting the url :)

  • Like 3
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...