How to add {breadcrumbs} text into the page Title ?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
URAN

How to add {breadcrumbs} text into the page Title ?

Post by URAN »

How to add TEXT from {breadcrumbs} into the PAGE TITLE ?

For the best usability I want to add {breadcrumbs} text into the page title. Also, it would be good for Search Machines.
amygdela

Re: How to add {breadcrumbs} text into the page Title ?

Post by amygdela »

tags in the header of your template?
URAN

Re: How to add {breadcrumbs} text into the page Title ?

Post by URAN »

I can. But it will include hyperlink tags also - Link

I think I should modify copy of /plugins/function.breadcrumbs.php file to exclude links tags. Unfortunetly, I`m not very in PHP...  :-\
URAN

Re: How to add {breadcrumbs} text into the page Title ?

Post by URAN »

Yes!! I did it!  ;D

Maybe not a PRO, but it works!

First, I made a copy of function.breadcrumbs.php and rename it to function.titlebreadcrumbs.php

After some modifications, it start to work! I can not attach this file, so here is the code (create function.titlebreadcrumbs.php and paste this code):

Code: Select all

<?php

function smarty_cms_function_titlebreadcrumbs($params, &$smarty)
{
	global $gCms; 

	$thispage = $gCms->variables['content_id'];

	$trail = "";

	#Check if user has specified a delimiter, otherwise use default
	if (isset($params['delimiter']))
	{
		$delimiter = $params['delimiter'];
	}
	else
	{
		$delimiter = " > ";
	}

	#Check if user has requested an initial delimiter
	if (isset($params['initial']))
	{
		if ($params['initial'] == "1")
		{
			$trail .= $delimiter . " ";
		}
	}

	#Make an array for all pages
	$allcontent = array();

	#Load current content
	$onecontent = ContentManager::LoadContentFromId($thispage, false);

	#Check if user has requested the list to start with a specific page
	if (isset($params['root']))
	{
		if (($onecontent == FALSE) || (strtolower($onecontent->Alias()) != strtolower($params['root'])))
		{
			$rootcontent = ContentManager::LoadContentFromAlias($params['root'], false);
			if ($rootcontent)
			{
				$trail .= '';
				if (isset($params['classid']))
				{
				$trail .= '';
				}
				$trail .= '>';
				$trail .= ($rootcontent->MenuText()!=''?$rootcontent->MenuText():$rootcontent->Name());
				$trail .= '' . $delimiter . ' ';
			}
		}
	}

	if ($onecontent !== FALSE)
	{
		array_push($allcontent, $onecontent);

		#Grab all parents and put them into the array as well
		while ($onecontent->ParentId() > 0)
		{
			$onecontent = ContentManager::LoadContentFromId($onecontent->ParentId(), false);
			// tdh add / modify next 5 lines
			if (isset($params['root']))
			{
				if (strtolower($onecontent->Alias()) != strtolower($params['root']))
				{
					array_push($allcontent, $onecontent);
				}
			}
			else
			{
				array_push($allcontent, $onecontent);
			}
		}

		#Pull them one by one in reverse order to construct a breadcrumb list
		while ($onecontent = array_pop($allcontent))
		{
			if ($onecontent->Id() != $thispage && $onecontent->Type() != 'seperator')
			{
                                if (($onecontent->getURL() != "") && ($onecontent->Type() != 'sectionheader')) {

                                        $trail .= ($onecontent->MenuText()!=''?$onecontent->MenuText():$onecontent->Name());
                                        $trail .= ''. $delimiter . ' ';
                                } else {
                                        if (isset($params['classid'])) {
										$trail .= '';
                                        }
                                        $trail .= ($onecontent->MenuText()!=''?$onecontent->MenuText():$onecontent->Name());
                                        if (isset($params['classid'])) {
										$trail .= '';
                                        }
                                        $trail .= ' ' . $delimiter . ' ';
                                }
			} else {
                                if (isset($params['currentclassid'])) {
										$trail .= '';
                                } else {
										$trail .= '';
                                }
                                $trail .= ($onecontent->MenuText()!=''?$onecontent->MenuText():$onecontent->Name());
                                if (isset($params['currentclassid'])) {
										$trail .= '';
                                } else {
										$trail .= '';	
                                }
			}
		}
	} else {
                if (isset($params['currentclassid'])) {
										$trail .= '';
                } else {
										$trail .= '';
                }
                $trail .= 'No pages';
                if (isset($params['currentclassid'])) {
										$trail .= '';
                } else {
										$trail .= '';
                }
	}

	return $trail;
}

function smarty_cms_help_function_titlebreadcrumbs() {
// tdh added the classid help text
?>
<h3>What does this do?</h3>
<p>Prints a title breadcrumb trail .</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your page title like: <code>{titlebreadcrumbs}</code></p>
<h3>What parameters does it take?</h3>
<p>
<ul>
<li><em>(optional)</em> <tt>delimiter</tt> - Text to seperate entries in the list (default ">").</li>
</ul>
</p>
<?php
}

function smarty_cms_about_function_titlebreadcrumbs() {
?>
<p>Author: Dzembak Yuri <<a href="mailto:dzembak@mail.ru">dzembak@mail.ru</a>></p>
<p>Version: 0.1</p>
<?php
}
# vim:ts=4 sw=4 noet
?>
Download this file and upload it to your CMSMS dir to:

/plugins/function.titlebreadcrumbs.php

After that you should go to the Admin Page and modify your current template:
FIND:

Code: Select all

<TITLE> MY SITE TITLE </TITLE>
REPLACE WITH:

Code: Select all

<TITLE> MY SITE TITLE > {titlebreadcrumbs}</TITLE>
or

Code: Select all

<TITLE> MY SITE TITLE » {titlebreadcrumbs delimiter=' » '}</TITLE>
- with custom delimiter (by default delimiter is ">")


Apply changes for your template and here it is!  :D
Last edited by URAN on Fri Mar 10, 2006 9:09 am, edited 1 time in total.
sawz

Re: How to add {breadcrumbs} text into the page Title ?

Post by sawz »

worked great for me! :)
Post Reply

Return to “Developers Discussion”