在下拉菜单(wordpress)顶部显示所选子页面的标题

时间:2023-01-16 14:14:40

I have a drop down menu on a page that I'm building for a client (using Wordpress). The title of the drop down is "Menu" and it doesn't link anywhere, it just displays the drop down menu-items on hover.

我在为客户端构建的页面上有一个下拉菜单(使用Wordpress)。下拉列表的标题是“菜单”,它不会在任何地方链接,只是在悬停时显示下拉菜单项。

When you select a subpage, is there a way to display the title of the active page where it says "Menu" on the startpage? For example, on Page 1 it would say Page 1 instead of Menu.

当您选择子页面时,有没有办法在首页上显示活动页面的标题,其中显示“菜单”?例如,在第1页上,它会说第1页而不是菜单。

I have looked around for options, but haven't found anything satisfying so far.

我四处寻找选择,但到目前为止还没有找到令人满意的东西。

The code for the menu:

菜单代码:

<nav class="x-nav-wrap desktop" role="navigation">
    <ul id="menu-primary-menu" class="x-nav">
        <li id="menu-item-36" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent menu-item-has-children menu-item-36"> <a href="#">
    <span>MENU</span></a>

            <ul class="sub-menu">
                <li id="menu-item-42" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-37 current_page_item menu-item-42"> <a href="http://test.frankochrakel.se/?page_id=37"><span>Page 1</span></a>
                </li>
                <li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-41"> <a href="http://test.frankochrakel.se/?page_id=39"><span>Page 2</span></a>
                </li>
            </ul>
        </li>
    </ul>
</nav>

http://test.frankochrakel.se/

I'm grateful for any ideas on how to solve this.

我很感激有关如何解决这个问题的任何想法。

1 个解决方案

#1


2  

Try to add this jquery in your header.php file.

尝试在header.php文件中添加此jquery。

Jquery in header.php

$(document).ready(function(){
    var get_current_menu_item = $('.sub-menu .current-menu-item span').text();
    if(get_current_menu_item)
        $('#menu-item-36 > a span').text(get_current_menu_item);
});

*If this is not working, replace '$' with 'jQuery' and try again.

*如果这不起作用,请将'$'替换为'jQuery',然后重试。

#1


2  

Try to add this jquery in your header.php file.

尝试在header.php文件中添加此jquery。

Jquery in header.php

$(document).ready(function(){
    var get_current_menu_item = $('.sub-menu .current-menu-item span').text();
    if(get_current_menu_item)
        $('#menu-item-36 > a span').text(get_current_menu_item);
});

*If this is not working, replace '$' with 'jQuery' and try again.

*如果这不起作用,请将'$'替换为'jQuery',然后重试。