wordpress 如何调用wp_nav_menu?

qxsslcnc  于 2022-12-17  发布在  WordPress
关注(0)|答案(1)|浏览(164)

我正在学习将HTML网站转换为WordPress。我想注册这个菜单,但不知道如何调用这些类。wp_nav_menu任何人都可以帮助我修复这个菜单到网站的代码。
以下函数用于在functions.php中注册菜单

<?php register_nav_menus(array('primary-menu'=>'Header Menu'))?>
<div class="ft_menu_ver_2">
                            <nav>
                                <ul id="menu-main-menu" class="menu"><li id="menu-item-1634" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-1634"><a href="maison/index.html">Home</a>
<ul class="sub-menu">
    <li id="menu-item-3407" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3407"><a href="maison/filtres/index.html">Water Filters</a></li>
    <li id="menu-item-3408" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3408"><a href="menage/soin-du-linge/index.html">Linen Care</a></li>
    <li id="menu-item-3884" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3884"><a href="climatisation/index.html">Air Conditioner</a></li>
    <li id="menu-item-6652" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-6652"><a href="menage/aspirateurs/index.html">Vacuum Cleaners</a></li>
    <li id="menu-item-6653" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-6653"><a href="machine-a-coudre/index.html">Sewing Machine</a></li>
    <li id="menu-item-10506" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-10506"><a href="maison/sport-a-la-maison/index.html">Sports at Home</a></li>
    <li id="menu-item-14337" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-14337"><a href="securite-domestique/index.html">Home Security</a></li>
</ul>
</li>
<li id="menu-item-3666" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-3666"><a href="chambre-a-coucher/index.html">Bedroom</a>
<ul class="sub-menu">
    <li id="menu-item-3406" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3406"><a href="meilleurs-matelas/index.html">Mattress</a></li>
    <li id="menu-item-11285" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11285"><a href="meilleurs-oreillers/index.html">Pillows</a></li>
</ul>
</li>
<li id="menu-item-1420" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-1420"><a href="cuisine/index.html">Kitchen</a>
<ul class="sub-menu">
    <li id="menu-item-11281" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11281"><a href="cuisine/lave-vaisselle/index.html">Dishwasher</a></li>
    <li id="menu-item-9327" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-9327"><a href="cuisine/cafe/index.html">Coffee</a></li>
    <li id="menu-item-2309" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2309"><a href="extracteurs-de-jus/index.html">Juice Extractors</a></li>
    <li id="menu-item-11282" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11282"><a href="cuisine/blenders/index.html">Blenders</a></li>
    <li id="menu-item-8364" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-8364"><a href="cuisine/barbecue/index.html">Barbecue</a></li>
    <li id="menu-item-14336" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-14336"><a href="cuisine/friteuse/index.html">Deep Fryer</a></li>
</ul>
</li>
<li id="menu-item-10502" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-10502"><a href="salle-de-bain/index.html">Bathroom</a>
<ul class="sub-menu">
    <li id="menu-item-11283" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11283"><a href="salle-de-bain/toilettes/index.html">Bathroom</a></li>
</ul>
</li>
<li id="menu-item-5579" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-5579"><a href="jardinage/index.html">Gardening</a>
<ul class="sub-menu">
    <li id="menu-item-8365" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-8365"><a href="jardinage/tondeuse/index.html">Mower</a></li>
</ul>
</li>
<li id="menu-item-3665" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3665"><a href="qui-sommes-nous/index.html">Who we are ?</a></li>
</ul>                            </nav>
                        </div>
                        <nav class="ft_menu_mobile_ver_2">
                            <div class="close"></div>
                            <ul id="menu-main-menu-1" class="menu"><li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-1634"><a href="maison/index.html">Home</a>
<ul class="sub-menu">
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3407"><a href="maison/filtres/index.html">Water Filters</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3408"><a href="menage/soin-du-linge/index.html">Linen Care</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3884"><a href="climatisation/index.html">Air Conditioner</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-6652"><a href="menage/aspirateurs/index.html">Vacuum Cleaners</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-6653"><a href="machine-a-coudre/index.html">Sewing Machine</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-10506"><a href="maison/sport-a-la-maison/index.html">Sports at Home</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-14337"><a href="securite-domestique/index.html">Home Security</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-3666"><a href="chambre-a-coucher/index.html">Bedroom</a>
<ul class="sub-menu">
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3406"><a href="meilleurs-matelas/index.html">Mattress</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11285"><a href="meilleurs-oreillers/index.html">Pillows</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-1420"><a href="cuisine/index.html">Kitchen</a>
<ul class="sub-menu">
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11281"><a href="cuisine/lave-vaisselle/index.html">Dishwasher</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-9327"><a href="cuisine/cafe/index.html">Coffee</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2309"><a href="extracteurs-de-jus/index.html">Juice Extractors</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11282"><a href="cuisine/blenders/index.html">Blenders</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-8364"><a href="cuisine/barbecue/index.html">Barbecue</a></li>
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-14336"><a href="cuisine/friteuse/index.html">Deep Fryer</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-10502"><a href="salle-de-bain/index.html">Bathroom</a>
<ul class="sub-menu">
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11283"><a href="salle-de-bain/toilettes/index.html">Bathroom</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-5579"><a href="jardinage/index.html">Gardening</a>
<ul class="sub-menu">
    <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-8365"><a href="jardinage/tondeuse/index.html">Mower</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3665"><a href="qui-sommes-nous/index.html">Who we are ?</a></li>
</ul>                        </nav>
                                                    <div class="ft_search_btn ftv2-search-actions">
                                <svg class="ftlg-btn-search" width="20" height="19" viewBox="0 0 20 19" fill="none">
                                    <path d="M18.7778 17.275L14.2639 12.5803C15.4245 11.2006 16.0604 9.46469 16.0604 7.65751C16.0604 3.43523 12.6252 0 8.40288 0C4.18059 0 0.745361 3.43523 0.745361 7.65751C0.745361 11.8798 4.18059 15.315 8.40288 15.315C9.98798 15.315 11.4985 14.8369 12.79 13.9294L17.3382 18.6597C17.5283 18.8571 17.784 18.966 18.058 18.966C18.3174 18.966 18.5634 18.8671 18.7502 18.6873C19.147 18.3055 19.1597 17.6722 18.7778 17.275ZM8.40288 1.99761C11.5238 1.99761 14.0628 4.53658 14.0628 7.65751C14.0628 10.7785 11.5238 13.3174 8.40288 13.3174C5.28194 13.3174 2.74297 10.7785 2.74297 7.65751C2.74297 4.53658 5.28194 1.99761 8.40288 1.99761Z"/>
                                </svg>
                                <svg class="ftlg-btn-close" width="24" height="24" viewBox="0 0 24 24" fill="none"
                                     xmlns="http://www.w3.org/2000/svg">
                                    <rect width="20.3644" height="2.26271" rx="0.4"
                                          transform="matrix(-0.707096 -0.707118 -0.707096 0.707118 20 18.4)"/>
                                    <rect width="20.3644" height="2.26271" rx="0.4"
                                          transform="matrix(0.707096 -0.707118 0.707096 0.707118 4 18.4)"/>
                                </svg>
                            </div>
                            <div class="ftlg-search-wrap ftv2-search-wrap">
                                <div class="ftlg-search-inner">
                                        <form role="search" method="get" class="search-form" action="https://mywebsite.com/">
        <input type="text" name="s"
               placeholder="" class="re-ajax-search" autocomplete="off" data-posttype="post">
        <input type="hidden" name="post_type" value="post"/>
        <button type="submit" class="btnsearch"><i class="fa fa-search"></i></button>
    </form>
    <div class="re-aj-search-wrap"></div>                                </div>
                            </div>
                                                
                </div>
            </div>
        </div>
    </div>
    <div class="ft_submenu_box_mask"></div>

这上面的html代码与css是用在我的html网站导航菜单。这个菜单是响应平板电脑和移动的侧菜单

ffx8fchx

ffx8fchx1#

如果wp_nav_menu函数的参数不足以实现菜单,则应创建一个自定义步行者类,从父类Walker_Nav_Menu扩展而来,然后覆盖其方法。最后,使用header.php中的wp_nav_menu函数,如下所示:

wp_nav_menu($args = array(
  'theme_location' => 'primary-menu',
  'walker' => new MyCustomNavMenu(),
));

相关问题