由於Joomla 2.5沒有提供規範URL的工作插件(除SEF404外),我會嘗試「模仿」我的模板並在需要時包含規範URL。Get Active Menu-URL
因爲每個菜單項都可以通過不同的URL和GET參數訪問,所以我希望在需要時包含規範URL。
我認爲最簡單的解決方案是獲取活動菜單項的URL,如果訪問的url不同於此,則將標準標籤包含到模板的index.php的標頭中。
我有基本的PHP知識,但我不知道如何獲取活動菜單項和訪問的URL的URL。任何人都可以告訴我如何獲得這些信息嗎?如果我有這個,那麼我可以簡單地比較它,如果不同,請添加標籤。
請張貼一些示例代碼如何獲取此信息。
編輯:這裏是一些基本信息(只與「主頁」有關),但對我來說這個代碼不起作用。 http://writenowdesign.com/joomla-tutorials/joomla-trips-and-tricks/add-canonical-url-link-to-joomla-home-page/
EDIT2:例如:
<?php
// Source: http://www.php.de/php-einsteiger/91123-erledigt-aktuelle-browser-url-ausgeben-funktion-zweckdienlich-2.html
function getUrl($arrAddParam = false, $xhtmlValid = false, $anchor = false, $dropCalledArgs = false) {
$url = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
$url .= $_SERVER['SERVER_NAME'];
$url .= $_SERVER['SCRIPT_NAME'];
// merge input and user param arrays
$arrParam = is_array($arrAddParam) ? $arrAddParam : array();
if ($dropCalledArgs === false) $arrParam = array_merge($_GET,$arrParam);
if (!empty($arrParam)) {
$arg_separator = $xhtmlValid ? '&' : '&';
$url .= "?". http_build_query($arrParam, '', $arg_separator);
}
// anchor
if ($anchor !== false) {
$url .= '#'.$anchor;
}
return $url;
}
// Get the application object
$app = JFactory::getApplication();
// Get's the menu object
$menu = $app->getMenu();
// Current URL
$activeUrl = getUrl();
// SHOULD get the active menu target as string, but it's an object
// THIS is my question how to get the URL of the current active menu item
$menuUrl = $menu->getActive();
?>
編輯3:Here是可能得到這個網址。但我需要SEO網址,而不是「普通網址」。
這是通過JS的當前網址 - 是的:) - 我會重新編輯主要問題,以清除它更詳細一點。 – Andy
看看「編輯2」:) – Andy