I would like to code my href as /about-us/ instead of index.php?pageid=21
but if the client decides to change the alias to about-the-company I need this to automatically adjust in the code.
Is there a way to grab the page_alias and page_name of a page by its page_id even if I am not currently on said page..?
So I would like something like:
$page_id = 21;
$page_alias = get_page_alias_by_id( $page_id );
$page_name = get_page_name_by_id( $page_id );
$html = '' . $page_name . '';
Thanks for your help.
RC
Get Page_Alias by PageID
-
Robbwell
Re: Get Page_Alias by PageID
Any takers, is this an impossible request..?
I am sure it can be done with the $gCms->GetHierarchyManager() somehow but I just cannot get it correctly.
This would be a great help and I am sure would benifit everyone.
Thanks for your help.
RC
I am sure it can be done with the $gCms->GetHierarchyManager() somehow but I just cannot get it correctly.
This would be a great help and I am sure would benifit everyone.
Thanks for your help.
RC
-
mahjong
Re: Get Page_Alias by PageID
No need to code your own function since can use instead of .
Code: Select all
{cms_selflink page="page_id"}Code: Select all
{cms_selflink page="page_alias"}
Last edited by mahjong on Thu Mar 01, 2007 3:20 pm, edited 1 time in total.
Re: Get Page_Alias by PageID
what exactly are you trying to accomplish that isn't already available through these options in config.php? (more info in the docs)
#Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules
$config['assume_mod_rewrite'] = true;
#Extension to use if you're using mod_rewrite for pretty URLs.
$config['page_extension'] = '/';
also included is a sample .htaccess file in ./docs/
note that this won't work on windows/iis -- all the more reason to use apache on linux.
also: the {cms_selflink} tag can be used to create links to other pages within the site, instead of 'hard coding' them -- if you reference a page by 'id' instead of 'alias' in the tag, the link will update if someone changes its alias.
#Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules
$config['assume_mod_rewrite'] = true;
#Extension to use if you're using mod_rewrite for pretty URLs.
$config['page_extension'] = '/';
also included is a sample .htaccess file in ./docs/
note that this won't work on windows/iis -- all the more reason to use apache on linux.
also: the {cms_selflink} tag can be used to create links to other pages within the site, instead of 'hard coding' them -- if you reference a page by 'id' instead of 'alias' in the tag, the link will update if someone changes its alias.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
-
Robbwell
Re: Get Page_Alias by PageID
What I am trying to do is put a page alias in my custom tag, since I cannot use {cms_selflink} within the php code, I need a way to grab the alias by the id. The following code is for a graphic horizontal menu with buttons that stay highlighted when they are on their own pages.
So in my template I have {main_nav button="1"}
But I would rather not code the href as href="index.php?page=40"
I would rather get_alias_by_pageid(40) so my link looks like href="/the-show/"
I managed to come up with the following which I ripped from /plugins/functions.cms_selflink.php:
and put it in /lib/misc.functions.php
You could easily change the name of the function and return a different variable.
This seems to work fine, but if I am doing something that already exists somewhere, please let me know.
RC
So in my template I have {main_nav button="1"}
But I would rather not code the href as href="index.php?page=40"
I would rather get_alias_by_pageid(40) so my link looks like href="/the-show/"
Code: Select all
// if a specific button is passed to be highlighted
if( isset( $params[ 'button' ] ) )
$button = $params[ 'button' ];
else
// default all buttons off
$button = 0;
$strHTML = '
<ul>
<li id="nav_the_show"><a href="' . get_alias_by_pageid(40) . '" class="img_rplc' . ( $button == 1? ' current' : '' ) . '">The Show</a></li>
<li id="nav_buy_ticket"><a href="index.php?page=18" class="img_rplc' . ( $button == 2? ' current' : '' ) . '">Buy Tickets</a></li>
<li id="nav_buy_subscription"><a href="index.php?page=19" class="img_rplc' . ( $button == 3? ' current' : '' ) . '">Buy a Subscription</a></li>
<li id="nav_plan_your_visit"><a href="index.php?page=16" class="img_rplc' . ( $button == 4? ' current' : '' ) . '">Plan Your Visit</a></li>
<li id="nav_groups"><a href="index.php?page=17" class="img_rplc' . ( $button == 5? ' current' : '' ) . '">Groups</a></li>
<li id="nav_education"><a href="index.php?page=34" class="img_rplc' . ( $button == 6? ' current' : '' ) . '">Education</a></li>
<li id="nav_support_us"><a href="index.php?page=27" class="img_rplc' . ( $button == 7? ' current' : '' ) . '">Support Us</a></li>
<li id="nav_work_with_us"><a href="index.php?page=20" class="img_rplc' . ( $button == 8? ' current' : '' ) . '">Work With Us</a></li>
</ul>
';
// write out the menu
echo $strHTML;
Code: Select all
function get_alias_by_pageid( $page = 0 )
{
global $gCms;
# check if the page exists in the db
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias( $page );
if (!isset($node)) return;
$content =& $node->GetContent();
if ($content !== FALSE)
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name();
$url = $content->GetUrl();
$menu_text = $content->MenuText();
$titleattr = $content->TitleAttribute();
return $alias;
}
else
{
return false;
}
}
You could easily change the name of the function and return a different variable.
This seems to work fine, but if I am doing something that already exists somewhere, please let me know.
RC
Re: Get Page_Alias by PageID
in an edit to the core file index.php to support bbclone, i use the following to grab the page alias, which is then passed on to the bbclone script:
$pageinfo->content_alias
dunno if it works in a tag or not... sorry.
$pageinfo->content_alias
dunno if it works in a tag or not... sorry.
Last edited by kermit on Thu Mar 01, 2007 3:57 pm, edited 1 time in total.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
Re: Get Page_Alias by PageID
If you only need this for a horizontal image menu, why not use the menumanager with a customized template? Most of the included menu templates already apply a CSS class for the currently-selected item. It seems like the code is trying to do what {menu} already does. 
Have you seen this tutorial?
Here's another approach with a rough version of a custom menu template (with extra indentation for readability):
Have you seen this tutorial?
Here's another approach with a rough version of a custom menu template (with extra indentation for readability):
Code: Select all
{if $count > 0}
</ul>
{foreach from=$nodelist item=node}
{if $node->current == true or $node->parent == true}
<li><a href="{$node->url}" class="menumain_selected"
style="background-image:url(mypath/menu_{$node->alias}.gif);">
{$node->menutext}</a></li>
{else}
<li><a href="{$node->url}"
style="background-image:url(mypath/menu_{$node->alias}.gif);">
{$node->menutext}</a></li>
{/if}
{/foreach}
</ul>
{/if}
Last edited by chead on Thu Mar 01, 2007 7:28 pm, edited 1 time in total.
Re: Get Page_Alias by PageID
i was thinkin' that too... he's just re-inventing the wheel.. and partially hard-coding it too. dunno what kind of images are being used, but one of those image-replacement do-dads and gd might be able to make 'em on the fly for fully dynamic image menus.chead wrote: If you only need this for a horizontal image menu, why not use the menumanager with a customized template? Most of the included menu templates already apply a CSS class for the currently-selected item. It seems like the code is trying to do what {menu} already does.![]()
Last edited by kermit on Thu Mar 01, 2007 4:12 pm, edited 1 time in total.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info

