SamC Posted October 30, 2016 Posted October 30, 2016 (edited) Can't seem to output the friendly urls here: // home.inc <?php $quickLinks = $pages->find("parent.template=quick-links"); // outputs 1045, 1046, 1047, 1048 so got the IDs ok... echo $quickLinks; foreach($quickLinks as $item) { echo "<li><a href='$item->internalPage'>$item->title</a></li>"; } ?> This outputs 'site.com/1045' rather than 'site.com/about-us/'. 'internalPage' is a page field type on the quick-links template, where I select a single page to link to. Not sure what I'm doing wrong here. Any help is appreciated, thanks! --EDIT-- Can I add that '$item->internalPage->url' outputs 'site.com/1045->url'. Edited October 30, 2016 by SamC Adding more detail
fbg13 Posted October 30, 2016 Posted October 30, 2016 If you selected "Single Page" in the field options you need // /parent/child $item->internalPage->url; // or http://domain.tld/parent/child $item->internalPage->httpUrl; else you need to loop the field or do $item->internalPage->first->url.
SamC Posted October 30, 2016 Author Posted October 30, 2016 Thanks for replies, but none of them work for some reason: <?php $quickLinks = $pages->find("parent.template=quick-links"); echo $quickLinks; foreach($quickLinks as $item) { // outputs site.com/1015->url. Title is correct 'About Us'. echo "<li><a href='$item->internalPage->url'>$item->title</a></li>"; // outputs site.com/1015->httpUrl. Title is correct 'About Us'. echo "<li><a href='$item->internalPage->httpUrl'>$item->title</a></li>"; } ?> I have selected single page in the options. I thought '$item->internalPage->url' would work but no luck still.
fbg13 Posted October 30, 2016 Posted October 30, 2016 Try putting $item->internalPage->url in curly braces {$item->internalPage->url} 2
SamC Posted October 30, 2016 Author Posted October 30, 2016 1 minute ago, fbg13 said: Try putting $item->internalPage->url in curly braces {$item->internalPage->url} Clever thanks! Why does this work and not without?
fbg13 Posted October 30, 2016 Posted October 30, 2016 It just parses "$item->internalPage" and echoes "->url" as a normal string, don't know if it's normal behavior or not. More about the variable parsing. 1
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