将HTML代码转换为WordPress菜单

时间:2018-10-23 作者:Stayll

我有这个HTML

    <div class="navbartop">
  <a href="/">Home</a>
  <div class="subnavtop">
    <button class="subnavtopbtn">Alfabetic <i class="fa fa-caret-down"></i></button>
    <div class="subnavtop-content">
      <a href="#a">A</a>
      <a href="#team">Team</a>
      <a href="#careers">Careers</a>
    </div>
  </div> 
  <div class="subnavtop">
    <button class="subnavtopbtn">Services <i class="fa fa-caret-down"></i></button>
    <div class="subnavtop-content">
      <a href="#bring">Bring</a>
      <a href="#deliver">Deliver</a>
      <a href="#package">Package</a>
      <a href="#express">Express</a>
    </div>
  </div> 
  <div class="subnavtop">
    <button class="subnavtopbtn">Partners <i class="fa fa-caret-down"></i></button>
    <div class="subnavtop-content">
      <a href="#link1">Contact me for Partners</a>
      <a href="#link2">Partners</a>
      <a href="#link3">Partners</a>
      <a href="#link4">Partners</a>
      <a href="#link1">Partners</a>
      <a href="#link2">Partners</a>
      <a href="#link3">Partners</a>
      <a href="#link4">Partners</a>
    </div>
  </div>
  <a href="contact.php">Contact</a>
和CSS

/* ---------------- NavTop ---------------- */
.navbartop {
    overflow: hidden;
    background-color: #000; 
}
.navbartop a {
    float: left;
    font-size: 14px;
    color: white;
    text-align: center;
    padding: 14px 14px;
    text-decoration: none;
}
.subnavtop {
    float: left;
    overflow: hidden;
}
.subnavtop .subnavtopbtn {
    font-size: 14px;    
    border: none;
    outline: none;
    color: white;
    padding: 12px 14px;
    background-color: inherit;
    font-family: inherit;
    margin: 0;
}

.navbartop a:hover, .subnavtop:hover .subnavtopbtn {
    background-color: red;
}

.subnavtop-content {
    display: none;
    position: absolute;
    left: 0;
    background-color: #61414180;
    width: 100%;
    z-index: 1;
}

.subnavtop-content a {
    float: left;
    color: white;
    text-decoration: none;
}

.subnavtop-content a:hover {
    background-color: #eee;
    color: #000;
}

.subnavtop:hover .subnavtop-content {
    display: block;
}
如何更改WordPress自定义菜单的代码?

1 个回复
SO网友:Alexander Holsgrove

如果要显示自定义菜单,需要使用wp_nav_menu function. 我还假设您已向注册了自定义菜单register_nav_menus function 例如:

register_nav_menus(
   array(
      \'main-menu\' => \'Main Menu\',
   )
);
一个基本的例子是

wp_nav_menu(array(
   \'menu\'            => \'Main Menu\',
   \'theme_location\'  => \'main-menu\',
   \'container\'       => \'nav\',
));
更改theme_location 匹配你设定的任何内容register_nav_menus.

结束

相关推荐

Appearance > Menus

我已经添加了自定义WordPress管理菜单和页面,但是,我希望它出现在“外观>菜单”部分,以便用户可以将其添加到其网站的菜单结构中。请让我知道如何做到这一点。以下是我在管理页面上添加的自定义菜单示例:现在,我想在管理部分的外观>菜单中添加这些自定义页面:如果有人能帮忙,我将不胜感激。幸亏damienoneill2001, 我可以在外观>菜单中添加分类项,但是,如何在示例中的Generes/Writer中添加内容?这就是我添加自定义管理菜单的方式,我希望它们中的每一个(产品、促销、产品类