Finding a page id from an alias - [ SOLVED ]

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm

Finding a page id from an alias - [ SOLVED ]

Post by tallphil »

Hi all,

I'm writing a template which will output a link requiring a page id. I know the alias of the page that I'm trying to get to, is there a way to access the id of a page using it's alias? (not the current page)
Last edited by tallphil on Fri Feb 05, 2010 5:00 pm, edited 1 time in total.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Finding a page id from an alias

Post by Wishbone »

You can make a UDT called something like 'idfromalias', containing:

Code: Select all

global $gCms;
$cntnt = $gCms->getContentOperations();

echo(GetPageIDFromAlias($cntnt->$params['alias']));
You can then access it in your template with {idfromalias alias='youralias'}
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm

Re: Finding a page id from an alias

Post by tallphil »

Sounds perfect! However, I now get the following error:

Code: Select all

Fatal error: Call to undefined function GetPageIDFromAlias() in /home/nanosim/public_html/lib/content.functions.php(771) : eval()'d code on line 4
I created the UDT exactly as suggested in your post.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Finding a page id from an alias

Post by Wishbone »

Whoops... I got that last line a little backwards. Replace the last line with:

Code: Select all

echo($cntnt->GetPageIDFromAlias($params['alias']));
I have it working on my test page.
Last edited by Wishbone on Fri Feb 05, 2010 3:42 pm, edited 1 time in total.
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm

Re: Finding a page id from an alias

Post by tallphil »

Brilliant, worked first time! Thank you for your help, I've spent hours on this thing and I finally have it working ;)

FYI, I simply wanted to make the {edit} tag display a link to the edit page for a different page. In other words, on page1 have the {edit} tag go to the Admin Edit page for page2.

This is my (now working) solution:

Code: Select all

{capture assign='editlink'}{edit text="Edit This Different Page"}{/capture}
{capture assign='grouppage_id'}content_id={idfromalias alias='somealias'}{/capture}
{capture assign='current_id'}content_id={$content_id}{/capture}
<h3>{$editlink|replace:$current_id:$grouppage_id}</h3>
Out of interest, how would I go about putting this into a nice tidy UDT? Would I be able to access the {edit} module from within a UDT? Doesn't really matter as it's working now anyway.
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm

Re: Finding a page id from an alias - [ SOLVED ]

Post by tallphil »

Arg! I forgot to test this whilst logged out, and the edit link disappears when not logged into the admin back end! Which makes my efforts kind of pointless. Ah well!
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Finding a page id from an alias - [ SOLVED ]

Post by Wishbone »

I guess you wouldn't want an edit link showing for users other than the admin. :)
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Finding a page id from an alias - [ SOLVED ]

Post by Dr.CSS »

Yes the {edit} tag only works if your logged into the back end, so I've always kind of found it silly...
Post Reply

Return to “CMSMS Core”