Jump to content

problem with getting page with pageid


mrkhan
 Share

Recommended Posts

in my page i store value of page by using page type field, field name is: page_side_menu

when i call that field in template using

$pid=$page->page_side_menu;
echo $pid;
 
i can see the page number
 
but when i use bellow code i return me page title of home page not selected page.
 
$pid=$page->page_side_menu;
$paged=$pages->get($pid);
echo $paged->title;

why i am getting title of home page not page with id in $pid.

Thanks

Link to comment
Share on other sites

There's no need for $pages->get() there; if your page_side_menu field is a page type field, it should already contain reference to said page.

In your case "echo $page->page_side_menu->title" should be enough, though you'll first want to check that it actually has something selected. This also depends on how this field is set up, i.e. can it contain one page or multiple pages, does it return NullPage or just null when empty, etc. Check the field settings for these.

.. oh, and the source of your problem is actually that if you output (echo) a Page object, which this field probably contains, ProcessWire will automatically output it's ID (see the ___toString method of Page object), but if you give it as an argument to $pages->get(), it's used in it's original object form, which probably won't work there (because it makes no sense at all).

Link to comment
Share on other sites

Dear

yes but i want to get contents of that page. thats why i am using 

$pid=$page->page_side_menu;
$paged=$pages->get($pid);
echo $paged->title;

when i have that page in $paged then i can get all fields store in that page.

Thanks

Link to comment
Share on other sites

@mrkhan, there seems to be a slight misunderstanding here. Your $pid isn't page ID, it's a Page. You don't need $pages->get() to grab the page, you already have it.

// title of the page
echo $page->page_side_menu->title;

// URL of the page
echo $page->page_side_menu->url;

// body field of the page (assuming that it has field called body)
echo $page->page_side_menu->body;

// .. or, if you really want to store it in $paged first:
$paged = $page->page_side_menu;
echo $paged->title;
See what I mean? :)
  • 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

×
×
  • Create New...