简体   繁体   English

如何从html模板创建此wordpress导航栏菜单?

[英]How to create this wordpress navbar menu from html template?

I have html website template which I am trying to convert into wordpress theme. 我有html网站模板,我正尝试将其转换为wordpress主题。 Everything is going fine, but now I ran into a problem. 一切都很好,但现在我遇到了问题。 I am trying to create a navbar menu. 我正在尝试创建导航栏菜单。 It isn't hard task if menu is simple, but this particular one is hard to accomplish for me. 如果菜单很简单,这并不是一项艰巨的任务,但是对于我来说,这一特殊任务很难完成。

The html of this navbar menu is follwing: 该导航栏菜单的html如下:

<div class="art-nav">
    <div class="art-nav-l"></div>
    <div class="art-nav-r"></div>
<div class="art-nav-outer">
<div class="art-nav-wrapper">
<div class="art-nav-inner">
    <ul class="art-hmenu">
        <li>
            <a href="./new-page.html" class="active"><span class="l"></span><span class="r"></span><span class="t">New Page</span></a>
        </li>   
        <li>
            <a href="./new-page-2.html"><span class="l"></span><span class="r"></span><span class="t">New Page 2</span></a>
        </li>   
    </ul>


</div>
</div>
</div>
</div>

Which i tried to do: 我试图做的:

<div class="art-nav">
    <div class="art-nav-l"></div>
    <div class="art-nav-r"></div>
<div class="art-nav-outer">
<div class="art-nav-wrapper">
<div class="art-nav-inner">
    <nav class="site-menu">
        <?php wp_nav_menu(); ?>
    </nav>


</div>
</div>
</div>
</div>

Then I changed the css too and gave .site-menu the properties which previously belonged to .art-menu, but it did not work, my menu does not look like it needs to. 然后,我也更改了CSS,并为.site-menu提供了以前属于.art-menu的属性,但是它不起作用,我的菜单看起来不需要。 There are so many wrappers around this menu and css of this menu is very very long. 此菜单周围有很多包装,并且此菜单的CSS非常长。 So everything is very confusing for me as I am a beginner. 因此,当我还是初学者时,一切都让我感到困惑。 How should I format my code to create a menu which looks like the one in html? 我应该如何格式化我的代码以创建类似于html的菜单? If someone wants to see the css file, then I will send it. 如果有人想查看css文件,那么我将其发送。 Also if someone needs more information for answering, I will send it. 另外,如果有人需要更多信息来回答,我也会发送给您。

The menu's css declarations probably include outer wrapping elements. 菜单的css声明可能包含外部包装元素。 Just changing one inner menu wrapper is not enough, you'd have to comb through the entire css to see what else you need to copy. 仅更改一个内部菜单包装是不够的,您必须梳理整个CSS才能查看还需要复制什么。

A simpler solution would be to keep the html template's classes intact and modify the wp_nav_menu arguments. 一个更简单的解决方案是保持html模板的类不变,并修改wp_nav_menu参数。

$menu_args = array(
    'container'       => false,
    'menu_class'      => 'art-hmenu',
);

wp_nav_menu( $menu_args );

For more details, check out the documentation: http://codex.wordpress.org/Function_Reference/wp_nav_menu 有关更多详细信息,请查看文档: http : //codex.wordpress.org/Function_Reference/wp_nav_menu

You must use Wordpress menu walker. 您必须使用Wordpress菜单浏览器。 For example: 例如:

class Walker_Quickstart_Menu extends Walker {

    // Tell Walker where to inherit it's parent and id values
    var $db_fields = array(
        'parent' => 'menu_item_parent', 
        'id'     => 'db_id' 
    );

    /**
     * At the start of each element, output a <li> and <a> tag structure.
     * 
     * Note: Menu objects include url and title properties, so we will use those.
     */
    function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
        $output .= sprintf( "\n<li><a href='%s'%s>%s</a></li>\n",
            $item->url,
            ( $item->object_id === get_the_ID() ) ? ' class="current"' : '',
            $item->title
        );
    }

}

And details in here: http://codex.wordpress.org/Class_Reference/Walker 以及此处的详细信息: http : //codex.wordpress.org/Class_Reference/Walker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM