Jump to content

Solved: FieldType : Reference page


n00dles101
 Share

Recommended Posts

Hi,

How do I use the reference page fieldtype.

I'm trying to build a list of links to a some blog entires and referencing the pages which is giving me the ID of the page

To get the URL of the page I was using

$results = $pages->find("template=slideshow");
     foreach($results as $slide) {
       $url=$slide->slideshow_ref;
       
       echo "<li><div class='newsflash_container'><img src='{$slide->headerimage->url}' alt='' /><div class='newsflash'><h1>{$slide->headline}</h1>{$slide->smalldescription}<p><a href='{$url}' class='button'>More...</a></p></div></div></li>";
}

$url just gives me the ID of the page.

I also tried

$url=$pages->get($slide->slideshow_ref)->url; 

But thats just coming back blank.

Edit:

If I manually add the returned ID as in:

$url=$pages->get(5768)->url; 

All works as expected.

Edit Again !!

Ok, have it sorted, need to use the following syntax for it to work correctly.

$url=$pages->get("id={$slide->slideshow_ref}")->url;

Whats the best way to achieve this?

Rgds,

Mike

.

Link to comment
Share on other sites

I think I may not totally follow what you are doing here, but if I understand correctly, these two things may help:

1. Assuming that slideshow_ref is a page reference field, it should actually be a Page object. The reason it appears to be returning the ID is because that's the typecast string value of a Page object. However, it's actually a Page object Just like $slide is. So there is no need for you to run a separate $pages->get(), because you've already got it. :) You can just do $slide->slideshow_ref->url.

2. While not applicable in this case, I wanted to explain why Pages may be typecast as strings that return the ID. The reason for this is so that you can use them in selectors. So lets say that you wanted to find all pages that referenced the current page in their slideshow_ref field:

$pages->find("slideshow_ref=$page"); 

Or all other pages (except the current) using the slideshow template that had the same slideshow_ref as the current page:

$pages->find("template=slideshow, slideshow_ref={$page->slideshow_ref}, id!=$page"); 

I don't know if these are useful, but just wanted to use them as examples.

Link to comment
Share on other sites

Thanks Ryan,

I'm building a sliding banner for a site.

o - created a new template called slideshow

o - Each page of the slideshow has a heading, text, image and link.

o - link is a referenced page to one of the blog entries.

Just allows me to easily change the banners by quickly editing the slideshow pages rather than adding those fields to the normal pages.

I thought I tried  $slide->slideshow_ref->url as it seemed the most obvious one to try, but yeah it works as expected, busy today so probably wasn't thinking straight...

thanks again...

Mike

post-77-132614277285_thumb.png

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...