get page name and URL via ID

Permalink 3 users found helpful
Hi I want to display a number of page names and their URLs in a template, I want to use the page ID so if they are changed at any point form the sitemap they will also update.

Can anyone provide the code, there are a number of instances of this on the template.

<a href="<?php echo $PageIDurl=70; ?>"><?php echo $PageID=70; ?></a>

<a href="<?php echo $PageIDurl=71; ?>"><?php echo $PageID=71; ?></a>

<a href="<?php echo $PageIDurl=72; ?>"><?php echo $PageID=72; ?></a>

<a href="<?php echo $PageIDurl=74; ?>"><?php echo $PageID=74; ?></a>

Thank you.

OnsiteDesigner
View Replies: View Best Answer
nickratering replied on at Permalink Best Answer Reply
nickratering
Hi!
Take a look at this and I'm sure you'll manage this! ;-) Good luck!
http://www.concrete5.org/documentation/introduction/cheat-sheet/...

Nick.
OnsiteDesigner replied on at Permalink Reply
OnsiteDesigner
Hi Nick

Thanks for that, however that sheet is great for using if you need to manipulate the current page, but specifying another page is proving to be a bit more difficult, i.e. i don't want the current page name or its parent page name, i want a page name of an unrelated page.

Still an open question, answers greatly appreciated.

Thanks

Ben
jordanlev replied on at Permalink Reply
jordanlev
Try this:
<a href="<?php echo DIR_REL . Page::getCollectionPathFromID(71); ?>"><?php echo Page::getByID(71)->getCollectionName(); ?></a>
jordanlev replied on at Permalink Reply
jordanlev
A different version of this which is more efficient because it saves a database call is:
<?php $p = Page::getByID(71); ?>
<a href="<?php echo DIR_REL . $p->getCollectionPath(); ?>"><?php echo $p->getCollectionName(); ?></a>
OnsiteDesigner replied on at Permalink Reply
OnsiteDesigner
Superb! Thank Jordan, just what I was after.
PatrickHenry replied on at Permalink Reply
PatrickHenry
Perfect. Thank you very much kind sir Jordan!
I got it working perfectly for my needs, which was embedding the auto-nav in the theme columns of links in the footer. So for the About Section, I use auto-nav to display all it's sub-pages, and Jordan's code above to grade the parent page's name...in this case About.
$p = Page::getByID(555); #Your page id #
    $parent = DIR_REL . $p->getCollectionPath();
    $parentName = $p->getCollectionName();
    echo '<h6>'.$parentName.'</h6>';
   $bt_main = BlockType::getByHandle('autonav'); 
   $p = Page::getByID(127); #About Pg.
    $parent = DIR_REL . $p->getCollectionPath();
    $parentName = $p->getCollectionName();
    echo '<h6>'.$parentName.'</h6>';
   $bt_main = BlockType::getByHandle('autonav'); 
   $bt_main->controller->displayPages = 'custom'; // top, above, below, second_level, third_level, custom (Specify the displayPagesCID below)
   $bt_main->controller->displayPagesCID = '555'; // <-- Specify the CID of the page named: REPERTOIRE ( Gets the first level of pages under that section )
   $bt_main->controller->orderBy = 'display_asc'; 
   $p = Page::getByID(127); #About Pg.
    $parent = DIR_REL . $p->getCollectionPath();