在菜单中显示面包屑路径

发布于 2024-08-24 23:51:50 字数 3102 浏览 5 评论 0原文

我有产品的全局菜单和本地菜单。我想在显示产品时突出显示“我们的产品”链接,并在本地菜单中突出显示产品名称及其子页面,以便突出显示的链接将用作面包屑。我如何使用 jquery 和 codeigniter 或仅使用 jquery 来做到这一点。 这是本地菜单的代码:

<ul id="accordion">
<li class="pm"><h2><?php echo anchor('/products/thassos_wonder', 'Thassos Wonder+');?></h2>
<ul class="product_menu">
    <h2><?php echo anchor('/products/thassos_wonder', 'Thassos Wonder+');?></h2>
    <h2><?php echo anchor('/products/thassos_wonder_advantages', 'Thassos Wonder+ Advantages');?></h2>
    <h2><?php echo anchor('products/thassos_wonder_associated_products', 'Associated Products');?></h2>
    <h2><?php echo anchor('/products/thassos_wonder_brochure', 'Download TW+ Brochure');?></h2>
</ul>
</li>


<li class="pm"><h2><?php echo anchor('/products/marble_wonder', 'Marble Wonder+');?></h2>
<ul class="product_menu" id="mwmenu">
    <h2><?php echo anchor('/products/marble_wonder', 'Marble Wonder+');?></h2>
    <h2><?php echo anchor('/products/marble_wonder_advantages', 'Marble Wonder+ Advantages');?></h2>
    <h2><?php echo anchor('products/marble_wonder_associated_products', 'Associated Products');?></h2>
    <h2><?php echo anchor('/products/marble_wonder_brochure', 'Download MW+ Brochure');?></h2>
</ul>
</li>

<li class="pm"><h2><?php echo anchor('/products/polybond', 'Poly Bond+');?></h2>
<ul class="product_menu" id="pbmenu">
    <h2><?php echo anchor('/products/polybond', 'Poly Bond+');?></h2>
    <h2><?php echo anchor('/products/polybond_advantages', 'PolyBond+ Advantages');?></h2>
    <h2><?php echo anchor('products/polybond_areas_of_applications', 'Areas of Applications');?></h2>
    <h2><?php echo anchor('/products/polybond_brochure', 'Download Polybond+ Brochure');?></h2>
</ul>
</li>

这是本地菜单的 jquery 代码:

$(function() {
var pathname = location.pathname;
var highlight;
//highlight home
if(pathname == "/"){
    highlight = $('ul#accordion > li:first > a:first');
    $('a.active').parents('li').addClass('active');
}
else {
    var path = pathname.substring(1);
    if (path)
       highlight = $('ul#accordion a[href$="' + path + '"]');
}
highlight.attr('class', 'active');

// hide 2nd, 3rd, ... level menus
$('ul#accordion ul').hide();

// show child menu on click
$('ul#accordion > li > a.product_menu').click(function() {
    //minor improvement
    $(this).siblings('ul').toggle("slow");
    return false;
});

//open to current group (highlighted link) by show all parent ul's
$('a.active').parents('ul').show();

//if you only have a 2 level deep navigation you could
//use this instead
//$('a.selected').parents("ul").eq(0).show();

});

仍在学习 jquery,因此我们将不胜感激。 谢谢-G

I have a global menu and local menu for the products. I would like to highlight 'our products' link when I am showing the products and also highlight the name of the product and its subpages in the local menu so the highlighted links will work as the breadcrumbs. How can I do this with jquery and codeigniter or just jquery.
Here is the code of the local menu:

<ul id="accordion">
<li class="pm"><h2><?php echo anchor('/products/thassos_wonder', 'Thassos Wonder+');?></h2>
<ul class="product_menu">
    <h2><?php echo anchor('/products/thassos_wonder', 'Thassos Wonder+');?></h2>
    <h2><?php echo anchor('/products/thassos_wonder_advantages', 'Thassos Wonder+ Advantages');?></h2>
    <h2><?php echo anchor('products/thassos_wonder_associated_products', 'Associated Products');?></h2>
    <h2><?php echo anchor('/products/thassos_wonder_brochure', 'Download TW+ Brochure');?></h2>
</ul>
</li>


<li class="pm"><h2><?php echo anchor('/products/marble_wonder', 'Marble Wonder+');?></h2>
<ul class="product_menu" id="mwmenu">
    <h2><?php echo anchor('/products/marble_wonder', 'Marble Wonder+');?></h2>
    <h2><?php echo anchor('/products/marble_wonder_advantages', 'Marble Wonder+ Advantages');?></h2>
    <h2><?php echo anchor('products/marble_wonder_associated_products', 'Associated Products');?></h2>
    <h2><?php echo anchor('/products/marble_wonder_brochure', 'Download MW+ Brochure');?></h2>
</ul>
</li>

<li class="pm"><h2><?php echo anchor('/products/polybond', 'Poly Bond+');?></h2>
<ul class="product_menu" id="pbmenu">
    <h2><?php echo anchor('/products/polybond', 'Poly Bond+');?></h2>
    <h2><?php echo anchor('/products/polybond_advantages', 'PolyBond+ Advantages');?></h2>
    <h2><?php echo anchor('products/polybond_areas_of_applications', 'Areas of Applications');?></h2>
    <h2><?php echo anchor('/products/polybond_brochure', 'Download Polybond+ Brochure');?></h2>
</ul>
</li>

Here is the jquery code for the local menu:

$(function() {
var pathname = location.pathname;
var highlight;
//highlight home
if(pathname == "/"){
    highlight = $('ul#accordion > li:first > a:first');
    $('a.active').parents('li').addClass('active');
}
else {
    var path = pathname.substring(1);
    if (path)
       highlight = $('ul#accordion a[href$="' + path + '"]');
}
highlight.attr('class', 'active');

// hide 2nd, 3rd, ... level menus
$('ul#accordion ul').hide();

// show child menu on click
$('ul#accordion > li > a.product_menu').click(function() {
    //minor improvement
    $(this).siblings('ul').toggle("slow");
    return false;
});

//open to current group (highlighted link) by show all parent ul's
$('a.active').parents('ul').show();

//if you only have a 2 level deep navigation you could
//use this instead
//$('a.selected').parents("ul").eq(0).show();

});

Still learning jquery so type of help would be appreciated.
Thanks - G

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦欢 2024-08-31 23:51:50

您可以通过几种不同的方式来完成此操作,一种方法是始终标识您的正文标记和锚标记并使用 CSS 选择器来完成这项工作。

我喜欢用控制器的名称来识别我的身体标签,它非常方便。

在这种情况下,您的 body 标签会将 ID 设置为“产品”,将其与锚点上的 ID 结合起来,您可以像这样使用 CSS

#products #productLink {
    color: #ff8833;
}

另一种方法是 CI 中的辅助函数,它将根据当前链接检查链接URI 并向锚添加一个“活动”类,如下所示。

function menu_anchor($uri = '', $title = '', $attributes = array()) 
{
    if ( $uri == uri_string() )
    {
        $attributes['class'] = ( isset($attributes['class']) ) ? ' active' : 'active';
    }

    return anchor($uri, $title, $attributes);
}

You can do this a couple different ways, one way is to always ID your body tag and anchor tags and use CSS selectors to do the job.

I like to ID my body tags with the name of the controller, it comes in very handy.

In this case your body tag would have the ID set to 'products', combine this with IDs on your anchors and you can use CSS like this

#products #productLink {
    color: #ff8833;
}

Another way to do it would be a helper function in CI which would check the link against the current URI and add an 'active' class to the anchor, something like below.

function menu_anchor($uri = '', $title = '', $attributes = array()) 
{
    if ( $uri == uri_string() )
    {
        $attributes['class'] = ( isset($attributes['class']) ) ? ' active' : 'active';
    }

    return anchor($uri, $title, $attributes);
}
小帐篷 2024-08-31 23:51:50

我创建了一个辅助函数,可以帮助从 codeigniter 框架中的 URL 自动创建面包屑。

有关详细信息,请查看以下帖子 -

http://www.thephpx.com/2010/05/12/codeigniter-helper-create-breadcrumb-from-url/

谢谢,

费萨尔·艾哈迈德
http://www.thephpx.com/

I have created a helper function that helps create breadcrumbs automatically from URL in codeigniter framework.

for details please check out the following post -

http://www.thephpx.com/2010/05/12/codeigniter-helper-create-breadcrumb-from-url/

thanks,

faisal ahmed
http://www.thephpx.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文