2013-01-03 1 views
0

정식 URL (SEF404 옆)을 제공하는 Joomla 2.5 용 작동 플러그인이 없으므로 템플릿을 "해킹"하고 필요할 때 정식 URL을 포함 시키려고합니다.활성 메뉴 URL 얻기

모든 메뉴 항목에 다른 URL 및 GET-Parameters를 사용하여 액세스 할 수 있으므로 필요한 경우 표준 URL을 포함하고 싶습니다.

가장 쉬운 해결책은 활성 메뉴 항목의 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 ? '&amp;' : '&'; 
     $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이 URL을 얻을 수있는 가능성이다. 하지만 나는 "정상적인"이 아닌 SEO URL이 필요합니다.

답변

1

한편 해결책을 찾았습니다. 어쩌면이 내 상황에서 다른 사람을 도움이 :이) (현재의 URL를

JURI ::의 getInstance를 얻을 수있는 방법을 문서화 된 공식 책이다

<?php 

// Get SEO Page URL 
$pageUrl = JURI::current(); 
// Get URI Object 
$uri = & JFactory::getURI(); 
// Get URI String 
$pageUri = $uri->toString(); 

// Check if there is a difference 
if ($pageUrl != $pageUri){ 
    // Insert canonical tag when needed 
    echo '<link rel="canonical" href="'.$pageUrl.'" />'; 
} 

?> 
0

이런 뜻입니까, 아니면 뭔가 빠졌습니까?

var loc = window.location.href; 
$("ul.nav li a").each(function() { 
    if(this.href == loc) { 
    // If the current URL is the same as the active menu url 
    // Do something 
    } 
}); 
+0

이것은 JS를 통한 현재 URL입니다. 예 - 조금 더 자세히 설명하기 위해 주요 질문을 다시 편집하겠습니다. – Andy

+0

"Edit 2"를보세요 : – Andy

0

;

코드를 테스트 해보니 좋은 시작 인 것 같습니다.

+0

Andy - 저의 솔루션은 나에게 항상 효과가 없습니다. 두 변수가 같기 때문에 정식 적으로 삽입되지 않습니다. 우리는 php 값과 joomla 값을 얻어야한다고 생각합니다. 시도해보십시오. http://www.shikle.com/metagenerator.htm – landed