希望将静态HTML菜单复制到WordPress动态菜单中

时间:2021-08-03 作者:HPWD

我们正在将静态HTML站点转换为Wordpress。转换进行得很顺利(在大多数情况下),但我无法弄清楚的部分是如何构建菜单,以便我可以保留HTML站点的菜单外观(我所指的特定菜单也请参见图表)。

原始站点:http://humanetomorrow.org/enter image description here

我知道如何在WordPress admin dashboard中创建菜单并将其显示在页面上,我想我的问题可能更多的是如何使用徽标和;“扭曲”;我可以在上面用一些指针。

更新:添加了接受答案提供的代码后,我现在看到菜单上出现了非菜单项页面,即使它们没有添加到菜单中。Unwanted Menu Item

赞助商信息页面为;只有一页“;在另一个页面中链接到的,而不是菜单。

然后是我的WP代码:

            <?php
            wp_nav_menu( array(
                \'theme_location\' => \'primary\',
                \'container\' => \'nav\',
                \'container_class\' => \'\',
                \'menu_class\' => \'nav\',
                \'before\' => \'\',                                         // before the menu
                \'after\' => \'\',                                          // after the menu
                \'link_before\' => \'\',                                    // before each link
                \'link_after\' => \'\',                                     // after each link
                \'depth\' => 2,
            ) );
        ?>

2 个回复
SO网友:liquidRock

Lookup wp_nav_menu

Simply take the HTML you have now and remove the <ul> or whatever elements you are using to list the menu links. If you want it to be dynamic, your theme template will need something similar to the following placed where you want the links to load in place of what you had in your regular HTML site:


<?php wp_nav_menu(array(
         \'container\' => false,                           // remove nav container
         \'container_class\' => \'menu cf\',                 // class of container (should you choose to use it)
         \'menu\' => __( \'The Main Menu\', \'mytheme\' ),  // nav name
         \'menu_class\' => \'nav top-nav cf\',               // adding custom nav class
         \'theme_location\' => \'main-nav\',                 // where it\'s located in the theme
         \'before\' => \'\',                                 // before the menu
           \'after\' => \'\',                                  // after the menu
           \'link_before\' => \'\',                            // before each link
           \'link_after\' => \'\',                             // after each link
           \'depth\' => 0,                                   // limit the depth of the nav
         \'fallback_cb\' => \'\'                             // fallback function (if there is one)
)); ?>

You will also have to register your menu (or menus if you do multiple)

register_nav_menus(
    array(
        \'main-nav\' => __( \'The Main Menu\', \'mytheme\' ),   // main nav in header
        \'footer-links\' => __( \'Footer Links\', \'mytheme\' ) // secondary nav in footer
    )
);

The base theme I use to build WordPress themes has a separate file where you register the menus and image sizes etc.. Not sure if it would work in functions.php or not as I\'ve never tried, but I assume it would. Maybe someone else can chime in to answer that.

The way WordPress creates the navigation should work ok for what you need. Sometimes I hard-code menus when I can\'t use the WordPress menu HTML setup. Here is an example of a hard-coded menu, which you could turn into a simplified function if you wanted. The php code is just checking the URL basename to see what page we\'re currently on and add a class to that <li> so that the <li> and <a> tags can be easily styled.

<nav>
    <ul>
<?php if(basename(get_the_permalink())==\'about\') { echo \'<li class="current-menu-item"><a class="icon-about">\'; } else echo \'<li><a class="icon-about" href="/blog/">\';?>About</a></li>
<?php if(basename(get_the_permalink())==\'services\') { echo \'<li class="current-menu-item"><a class="icon-service">\'; } else echo \'<li><a class="icon-service" href="/services/">\';?>Services</a></li>
<?php if(basename(get_the_permalink())==\'contact\') { echo \'<li class="current-menu-item"><a class="icon-contact">\'; } else echo \'<li><a class="icon-contact2" href="/social/">\';?>Contact</a></li>
    </ul>
</nav>

Hope that helps point you in the right direction.

SO网友:challenge2022

该标题样式只是背景图像,而不是实际的css样式。

您可以将该图像作为背景图像再次应用于新站点的标题,或者通过css绘制,这需要强大的技术id想象。

此外,徽标是一个独立的png图像,位于精美的背景图像之上。

看看“css技巧”。

相关推荐

无法将设置添加到“NAV_MENUS”定制器面板

我试图在自定义程序的“菜单”面板中添加一个复选框,但由于某些原因,它没有显示出来。如果我尝试将其从“nav\\u菜单”更改为“title\\u tagline”或“colors”,复选框会显示得很好。是什么阻止它显示在“菜单”面板上?// add custom options to the Customizer function nssra_customizer_options($wp_customize) { // add \"menu primary flex\" checkb