хлебные крошки и модуль новости (решение)

Обсуждение CMS Made Simple в России.

Moderators: iturbay, wdwp

Post Reply
trofusha
New Member
New Member
Posts: 8
Joined: Thu Feb 17, 2011 11:16 am

хлебные крошки и модуль новости (решение)

Post by trofusha »

1. Создаем пользовательский тег "breadcumbsnews"
в него пихаем:

Code: Select all



	global $gCms; 
	$manager = &$gCms->GetHierarchyManager();

	$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 . " ";
		}
	}

	$root='##ROOT_NODE##';
#Check if user has requested the list to start with a specific page
	if (isset($params['root']))	{
		$root = $params['root'];
	}
	$root_url='';
#Check if user has requested to overrided the root URL
	if (isset($params['root_url']))	{
		$root_url = $params['root_url'];
	}


	$endNode = $manager->sureGetNodeById($thispage);

# build path
	if (isset($endNode))
	{
	        $content =& $endNode->getContent();
		$path=array($endNode);
		$currentNode = &$endNode->getParentNode();
		while (isset($currentNode) && $currentNode->getLevel() >= 0)
		{
			$content = &$currentNode->getContent();
			if (isset($content))
			{
			  //Add current node to the path and then check to see if
			  //current node is the set root
			  //as long as it's not hidden
			  if( $content->ShowInMenu() && $content->Active() )
			    {
				$path[] = $currentNode;
			    }
			  if (strtolower($content->Alias())!=strtolower($root))
			    {
			      //Get the parent node and loop
			      $currentNode = &$currentNode->getParentNode();
			    }
			  else
			    {
			      //No need to get the parent node -- we're the set root already
			      break;
			    }
			}
			else
			{
			  //There are more serious problems here, dump out while we can
			  break;
			}
		}

		if ($root!='##ROOT_NODE##') {
			// check if the last added is root. if not, add id
			$currentNode = $manager->sureGetNodeByAlias($root);

			if (isset($currentNode))
			{
				$content = &$currentNode->getContent();
				if (isset($content) && (strtolower($content->Alias()) == strtolower($root)))
				{
					$node = $manager->sureGetNodeByAlias($root);
					if (isset($node)) {
						$content = $node->getContent();
						if( $content && $content->Id() != $thispage) 
							$path[] = $node; # do not add if this is the current page
					}
				}
			}
		}
		$classid=isset($params['classid'])?(' class="' . $params['classid'] . '"'):'';
		$currentclassid=isset($params['currentclassid'])?(' class="' . $params['currentclassid'] . '"'):'';

		// now create the trail (by iterating through the path we built, backwards)
		for ($i=count($path)-1;$i>=0;$i--) {
			$node = &$path[$i];
			if (isset($node))
			{
				$onecontent = &$node->getContent();
				if ( $onecontent->Type() != 'seperator') {
					if (($onecontent->getURL() != "") && ($onecontent->Type() != 'sectionheader')) {
					  if ($onecontent->DefaultContent() && false == empty($root_url))
					    {
					      $trail .= '<a href="' . $root_url . '"';     
					    }
					      else
						{
						  $trail .= '<a href="' . $onecontent->getURL() . '"';
						}
						$trail .= $classid;
						$trail .= '>';
						$trail .= cms_htmlentities($onecontent->MenuText()!=''?$onecontent->MenuText():$onecontent->Name());
						$trail .= '</a> ';
					} else {
						$trail .= "<span $classid>";
						$trail .= cms_htmlentities($onecontent->MenuText()!=''?$onecontent->MenuText():$onecontent->Name());
						$trail .= '</span>';
						$trail .= ' ';
					}
					$trail .= $delimiter . ' ';
				} else {
					if (isset($params['currentclassid'])) {
						$trail .= "<span $currentclassid>";
					} else {
						$trail .= '<span class="lastitem">';
					}
					$trail .= cms_htmlentities($onecontent->MenuText()!=''?$onecontent->MenuText():$onecontent->Name());
					if (isset($params['currentclassid'])) {
						$trail .= '</span>';
					} else {
						$trail .= '</span>';
					}
				}
			}
		}
	}

	if (isset($params['starttext']) && $params['starttext'] != '')
	{
		$trail = $params['starttext'] . ': ' . $trail;
	}

	echo $trail;  

# vim:ts=4 sw=4 noet


в шаблоне используем:

Code: Select all

{if isset ($pagetitle)}
{breadcumbsnews}{$pagetitle}
{else}
{breadcrumbs}
{/if}
а переменная $pagetitle определяется в шаблоне новости:

Code: Select all

{assign var="pagetitle" value=$entry->title|escape}
{assign var="isnews" value="1"}
также должно быть в конфиге

Code: Select all

$config['process_whole_template'] = false;
а в шаблоне не должно быть (в начале)

Code: Select all

{process_pagedata}
ну и еще зачем то вот это вместо тега контент (хотя может и без этого работать будет):

Code: Select all

{content assign="capturedcontent"}						
{$capturedcontent}
В итоге получим нормальные хлебные крошки для новостей
Post Reply

Return to “Russian - русский”