2011-03-04 18 views
2

Joomla 1.5のmod_mainmenuモジュールをオーバーライドしており、.activeまたは#current CSSクラスまたはIDをページに表示できません。私はあなたが現在アクティブなメニュー選択でどの項目伝えることができるようにmod_mainmenuが自動的にどこかで、この中activeまたはcurrentのいずれかを挿入することを読んだJoomlaのアクティブなメニュー項目をハイライト表示

<ul id="top-nav" class="flatList"> 
    <li access="0" level="1" id="1"> 
    <a href="#"> 
     <span class="embed embed-top-nav">Home</span> 
     <p>news, highlights</p> 
    </a> 
    </li> 
    <li access="0" level="1" id="4"> 
    <a href="/content/index.php?option=com_content&amp;view=article&amp;id=1&amp;Itemid=4"> 
     <span class="embed embed-top-nav">Watch UNC-TV</span> 
     <p>schedule, programs</p> 
    </a> 
    </li> 
</ul> 

:メニューのため、次のHTMLを示しています。しかし、私は生成されたHTMLのいずれかを見ていない。私はアクティブな要素にいくつかのCSSを適用したいと思いますが、これを行う方法はないようです。何かご意見は?

ありがとうございました。

UPDATE:ここで私が作成したmod_mainmenuのコードです:

<?php 

// no direct access 
defined('_JEXEC') or die('Restricted access'); 

if (! defined('fancyMenuPatch')) 
{ 
    function fancyMenuPatch($result,$tag){ 
    $menu = JSite::getMenu(); 
    $active = $menu->getActive(); 

    // Add to the start of the UL tag. 
    $begin_ul = "<ul id=\"top-nav\" class=\"flatList\">"; 
    $begin_span = "<span class=\"embed embed-top-nav\">"; 

    $home_p = "Home</span><p>news, highlights</p></a>"; 
    $watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>"; 
    $learn_p = "Learn</span><p>education, unc-tv kids</p></a>"; 
    $support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>"; 
    $contact_p = "Contact</span><p>feedback, connect, share</p></a>"; 

    // do the replacements 
    $result = str_replace("<ul class=\"menu\">",$begin_ul, $result); 
    $result = str_replace("<span>", $begin_span, $result); 
    $result = str_replace("Home</span></a>",$home_p,$result); 
    $result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result); 
    $result = str_replace("Learn</span></a>",$learn_p,$result); 
    $result = str_replace("Support Us</span></a>",$support_p,$result); 
    $result = str_replace("Contact</span></a>",$contact_p,$result); 

    return $result; 
    } 
    define('fancyMenuPatch', true); 
} 

if (! defined('modMainMenuXMLCallbackDefined')) 
{ 
function modMainMenuXMLCallback(&$node, $args) 
{ 
    $user = &JFactory::getUser(); 
    $menu = &JSite::getMenu(); 
    $active = $menu->getActive(); 
    $path = isset($active) ? array_reverse($active->tree) : null; 

    if (($args['end']) && ($node->attributes('level') >= $args['end'])) 
    { 
    $children = $node->children(); 
    foreach ($node->children() as $child) 
    { 
     if ($child->name() == 'ul') { 
     $node->removeChild($child); 
     } 
    } 
    } 

    if ($node->name() == 'ul') { 
    foreach ($node->children() as $child) 
    { 
     if ($child->attributes('access') > $user->get('aid', 0)) { 
     $node->removeChild($child); 
     } 
    } 
    } 

    if (($node->name() == 'li') && isset($node->ul)) { 
    $node->addAttribute('class', 'parent'); 
    } 

    if (isset($path) && (in_array($node->attributes('id'), $path) || in_array($node->attributes('rel'), $path))) 
    { 
    if ($node->attributes('class')) { 
     $node->addAttribute('class', $node->attributes('class').' active'); 
    } else { 
     $node->addAttribute('class', 'active'); 
    } 
    } 
    else 
    { 
    if (isset($args['children']) && !$args['children']) 
    { 
     $children = $node->children(); 
     foreach ($node->children() as $child) 
     { 
     if ($child->name() == 'ul') { 
      $node->removeChild($child); 
     } 
     } 
    } 
    } 

    if (($node->name() == 'li') && ($id = $node->attributes('id'))) { 
    if ($node->attributes('class')) { 
     $node->addAttribute('class', $node->attributes('class').' item'.$id); 
    } else { 
     $node->addAttribute('class', 'item'.$id); 
    } 
    } 

    if (isset($path) && $node->attributes('id') == $path[0]) { 
    $node->addAttribute('id', 'current'); 
    } else { 
    $node->removeAttribute('id'); 
    } 
    $node->removeAttribute('rel'); 
    $node->removeAttribute('level'); 
    $node->removeAttribute('access'); 
} 
    define('modMainMenuXMLCallbackDefined', true); 
} 
ob_start(); 

modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback'); 
$menu_html = ob_get_contents(); 
ob_end_clean(); 

if($params->get('menutype')=="mainmenu"){ 
    $tag = $params->get('tag_id'); 
} 

//output the menu! 
echo fancyMenuPatch($menu_html,$tag); 
?> 
+0

あなたがオーバーライド・ファイル内のコードを投稿することができますか?アクティブなメニューIDとクラスは、コアテンプレートファイルに設定されています。上書きする場合は、それを考慮する必要があります。 –

+0

ありがとう、ブレント。私は明日コードを掲示します。今すぐアクセスすることはできません。 – Alex

+0

メニュー構造はmod_mainmenuによって生成されないようです。もう一度チェックしてください。これは、他のメニューモジュールによって生成される可能性があります。 – Prakash

答えて

3

はこれを試してみてください、ここでmod_mainmenuのコード(オーバーライド)です:

<?php 

// no direct access 
defined('_JEXEC') or die('Restricted access'); 

if (! defined('fancyMenuPatch')) 
{ 
    function fancyMenuPatch($result,$tag){ 
    $menu = JSite::getMenu(); 
    $active = $menu->getActive(); 

    // Add to the start of the UL tag. 
    $begin_ul = "<ul id=\"top-nav\" class=\"flatList\">"; 
    $begin_span = "<span class=\"embed embed-top-nav\">"; 

    $home_p = "Home</span><p>news, highlights</p></a>"; 
    $watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>"; 
    $learn_p = "Learn</span><p>education, unc-tv kids</p></a>"; 
    $support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>"; 
    $contact_p = "Contact</span><p>feedback, connect, share</p></a>"; 

    // do the replacements 
    $result = str_replace("<ul class=\"menu\">",$begin_ul, $result); 
    $result = str_replace("<span>", $begin_span, $result); 
    $result = str_replace("Home</span></a>",$home_p,$result); 
    $result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result); 
    $result = str_replace("Learn</span></a>",$learn_p,$result); 
    $result = str_replace("Support Us</span></a>",$support_p,$result); 
    $result = str_replace("Contact</span></a>",$contact_p,$result); 

    return $result; 
    } 
    define('fancyMenuPatch', true); 
} 

if (! defined('modMyMainMenuXMLCallbackDefined')) 

    { 

    function modMyMainMenuXMLCallback(&$node, $args) 

    { 

    $user = &JFactory::getUser(); 

    $menu = &JSite::getMenu(); 

    $active = $menu->getActive(); 

    $path = isset($active) ? array_reverse($active->tree) : null; if (($args['end']) && ($node->attributes('level') >= $args['end'])) 
    { 

    $children = $node->children(); 

    foreach ($node->children() as $child) 

    { 

    if ($child->name() == 'ul') { 

    $node->removeChild($child); 

    } 

    } 

    } 

if ($node->name() == 'ul') { 

    foreach ($node->children() as $child) 

    { 

    if ($child->attributes('access') > $user->get('aid', 0)) { 

    $node->removeChild($child); 

    } 

    } 

    } 

if (($node->name() == 'li') && isset($node->ul)) { 

    $node->addAttribute('class', 'parent'); 

    } 

if (isset($path) && in_array($node->attributes('id'), $path)) 

    { 

    if ($node->attributes('class')) { 

    $node->addAttribute('class', $node->attributes('class').' active'); 

    } else { 

    $node->addAttribute('class', 'active'); 

    } 

    } 

    else 

    { 

    if (isset($args['children']) && !$args['children']) 

    { 

    $children = $node->children(); 

    foreach ($node->children() as $child) 

    { 

    if ($child->name() == 'ul') { 

    $node->removeChild($child); 

    } 

    } 

    } 

    } 

if (($node->name() == 'li') && ($id = $node->attributes('id'))) { 

    if ($node->attributes('class')) { 

    $node->addAttribute('class', $node->attributes('class').' item'.$id); 

    } else { 

    $node->addAttribute('class', 'item'.$id); 

    } 

    } 

if (isset($path) && $node->attributes('id') == $path[0]) { 

    $node->addAttribute('id', 'current'); 

    } else { 

    $node->removeAttribute('id'); 

    } 

    $node->removeAttribute('level'); 

    $node->removeAttribute('access'); 



    } 

    define('modMyMainMenuXMLCallbackDefined', true); 

} 

ob_start(); 

modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback'); 
$menu_html = ob_get_contents(); 
ob_end_clean(); 

if($params->get('menutype')=="mainmenu"){ 
    $tag = $params->get('tag_id'); 
} 

//output the menu! 
echo fancyMenuPatch($menu_html,$tag); 
?> 
+0

ありがとう、Prakash。これは動作します!しかし、なぜ?私のmod_mainmenuオーバーライドで何が間違っていたのですか? – Alex

+0

Do'h !!私は自分のやり方の誤りを見る:私はmod関数を 'modMainMenuXMLCallback'と綴り、' modMyMainMenuXMLCallback'を呼び出してそれをレンダリングする。 Dang。 – Alex

1

は、あなたのテンプレートフォルダをチェックし、template.cssファイルは、あなたがそこに見つけることができる、そこにあります!

+0

template.cssファイルを持たないカスタムテンプレートを使用しています。 – Alex

関連する問題