n00dles101 Posted January 25, 2011 Share Posted January 25, 2011 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 More sharing options...
ryan Posted January 25, 2011 Share Posted January 25, 2011 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 More sharing options...
n00dles101 Posted January 25, 2011 Author Share Posted January 25, 2011 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 Link to comment Share on other sites More sharing options...
ryan Posted January 25, 2011 Share Posted January 25, 2011 Sounds like a good way to put together the slideshow, and it looks good too! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now