Jump to content

Getting URL of page field type


SamC
 Share

Recommended Posts

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 by SamC
Adding more detail
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

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