How to exclude pages from cms_selflink prev/next ?

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
mathieu.bautista
Forum Members
Forum Members
Posts: 10
Joined: Wed Aug 13, 2008 8:42 am

How to exclude pages from cms_selflink prev/next ?

Post by mathieu.bautista »

Hello,

I have put the {cms_selflink dir="prev"} and {cms_selflink dir="next"} tags in my template. Here is my menu :

1- Home (page)
2- News (page)
3- Infos (page with coords, access map and contact form)
4- Access map (internal link/anchor)
5- Contact (internal link/anchor)
6- Credits (page)

My problem is that I can't navigate (using prev/next links) to the credits page, because cms_selflink tags include links with anchors (items 4 and 5 in above menu).

Any idea how I could exclude those two links from the cms_selflink tag please ?

Something like {cms_selflink dir="prev" exclude="4,5"}{cms_selflink dir="next" exclude="4,5"} would fit, but I don't think it exists...

Note : Unforunately I can't remove the anchors from the menu itself, that's a customer requirement...

Thank you.
mathieu.bautista
Forum Members
Forum Members
Posts: 10
Joined: Wed Aug 13, 2008 8:42 am

Re: How to exclude pages from cms_selflink prev/next ?

Post by mathieu.bautista »

I have tried this :

Code: Select all

{cms_selflink dir="prev" assign="prevlink"}{if !$prevlink|strstr:"#"}{$prevlink}{/if}
{cms_selflink dir="next" assign="nextlink"}{if !$nextlink|strstr:"#"}{$nextlink}{/if}
This hides the unwanted links, but doesn't solve my problem : I would like the prev/next link to "skip" anchors and dispay the real prev/next page...
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: How to exclude pages from cms_selflink prev/next ?

Post by RonnyK »

I dont know how your pages are showing seperate from what you have listed, but what if you mark the page 4/5 as non-showing in menu. Then the menu-call could be a show_all=1call, to show the hidden pages as well. Then the cms_selflink will skip the hidden pages IIRC.

This is depending if you have other non-showing pages, as they woul become visible as well in the call..

Ronny
mathieu.bautista
Forum Members
Forum Members
Posts: 10
Joined: Wed Aug 13, 2008 8:42 am

Re: How to exclude pages from cms_selflink prev/next ?

Post by mathieu.bautista »

I finally copied some code from plugins/function.cms_selflink.php and created my own user tags :

{prev_link} :

Code: Select all

global $gCms;
$manager = & $gCms->GetHierarchyManager();
$pages = & $manager->getFlatList();
$number = 0;
for ($i=0;$i<count($pages);$i++){
	if ($pages[$i]->getTag() == $gCms->variables['content_id']){
		$number = $i;
		break;
	}
}
$pageid = null;
if ($number > 0){
	for ($i = $number - 1; $i >= 0; $i--){
		$content =& $pages[$i]->getContent();
		if (isset($content) && $content != NULL){
			if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink() && !strstr($content->GetURL(),'#')){
				$pageid = $content->Id();
				$alias = $content->Alias();
				$name = $content->Name();
				$menu_text = $content->MenuText();
				$url = $content->GetURL();
				$titleattr = $content->TitleAttribute();
				break;
			}
		}else{
			break;
		}
	}
}
if (!empty($pageid)){
	echo '<a class="button" title="'.$name.'" href="'.$url.'"><span>Previous page</span></a>';
}
{next_link} :

Code: Select all

global $gCms;
$manager = & $gCms->GetHierarchyManager();
$pages = & $manager->getFlatList();
$number = 0;
for ($i=0;$i<count($pages);$i++){
	if ($pages[$i]->getTag() == $gCms->variables['content_id']){
		$number = $i;
		break;
	}
}
$pageid = null;
if ($number > 0){
	for ($i = $number + 1; $i < count($pages); $i++){
		$content =& $pages[$i]->getContent();
		if (isset($content) && $content != NULL){
			if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink() && !strstr($content->GetURL(),'#')){
				$pageid = $content->Id();
				$alias = $content->Alias();
				$name = $content->Name();
				$menu_text = $content->MenuText();
				$url = $content->GetURL();
				$titleattr = $content->TitleAttribute();
				break;
			}
		}else{
			break;
		}
	}
}
if (!empty($pageid)){
	echo '<a class="button" title="'.$name.'" href="'.$url.'"><span>Next page</span></a>';
}
This is not very "smart" but it works...
mathieu.bautista
Forum Members
Forum Members
Posts: 10
Joined: Wed Aug 13, 2008 8:42 am

Re: How to exclude pages from cms_selflink prev/next ?

Post by mathieu.bautista »

Hello Ronny,

Thank you, that would have been cleverer, but unfortunately I have lots of pages that can't be shown on menu...
Post Reply

Return to “CMSMS Core”