かなり簡単です...
カスタムコンポーネントではなく、記事のカテゴリとセクションを追加したいとします。
要求された現在のURLが記事用であるかどうかを確認します。記事IDがわかっている記事の場合は、この記事IDを使用してデータベースに移動して取得catid
します。#__content
これを使用しcat_id
て移動し#__categories
て取得しsection
(これはセクションIDです)、に移動し#__sections
て適切なセクション名を取得します。これはすべて、1つのSQLステートメントで実行できます。
$breadcrumbs =& JFactory::getApplication()->getPathway();
$breadcrumbs->addItem("SECTION_NAME", JRoute::_("index.php?option=com_content&view=section&id=SECTION_ID"));
$breadcrumbs->addItem("CATEGOY_NAME", JRoute::_("index.php?option=com_content&view=category&id=CATEGORY_ID"));
$breadcrumbs->addItem("Article");
または、ブレッドクラムアイテムのURLがわかっている場合。それを解析してIDSを取得できます。ここでの秘訣はJFactory::getURI()
、物事が醜くなるため、デフォルトのURIオブジェクトを取得しないことです。を使用してJFactory::getURI('YOU_URI_NAME')
ください。
<?php
// You need to get Your own uri, you do not want to modify default URI
// because this will messup a lot of things
$uri = JFactory::getURI('MyCustomURI');
// Test # 1 [ID = SECTION_ID]
$url = "index.php?option=com_content&view=section&id=SECTION_ID";
$uri->parse($url);
echo "CURRENT SECTION = " . (int) $uri->getVar('id');
// Test # 2 [ID = 123]
$url = "index.php?option=com_content&view=section&id=123";
$uri->parse($url);
echo "CURRENT SECTION = " . (int) $uri->getVar('id');
?>