如何更改WordPress菜单结构(ul > li到nav > a)

huangapple go评论52阅读模式
英文:

How to Change WordPress Menu Structure (ul > li to nav > a)

问题

我正在尝试创建WordPress菜单使用:

wp_nav_menu(
    array(
        'menu' => '顶部菜单',
        'container' => 'nav',
        'container_class' => '',
        'theme_location' => '顶部菜单',
        'items_wrap' => '<nav>%3$s</nav>'
    )
);

问题是WordPress向导航中添加了ui > ul结构,而我想使用以下结构:

<nav>
    <a href="page1.html">页面1</a>
    <a href="page2.html">页面2</a>
    <a href="page3.html">页面3</a>
    <a href="page4.html">页面4</a>
</nav>

有没有想法如何实现这样的结构,以便我可以用无序/有序列表以外的任何内容来组织菜单?

英文:

I'm trying to create a WordPress menu using:

        &lt;?php 
            wp_nav_menu(
                array(
                    &#39;menu&#39; =&gt; &#39;Top Mid&#39;,
                    &#39;container&#39; =&gt; &#39;nav&#39;,
                    &#39;container_class&#39; =&gt; &#39;&#39;,
                    &#39;theme_location&#39; =&gt; &#39;Top Mid&#39;,
                    &#39;items_wrap&#39; =&gt; &#39;&lt;ul&gt;%3$s&lt;/ul&gt;&#39;
                )
            );
        ?&gt;

The problem is that WordPress adding a ui > ul structure to the navigation whereas I want to use the following structure:

&lt;nav&gt;
   &lt;a href=&quot;page1.html&quot;&gt;Page 1&lt;/a&gt;
   &lt;a href=&quot;page2.html&quot;&gt;Page 2&lt;/a&gt;
   &lt;a href=&quot;page3.html&quot;&gt;Page 3&lt;/a&gt;
   &lt;a href=&quot;page4.html&quot;&gt;Page 4&lt;/a&gt;
&lt;/nav&gt;

Any thoughts on how this can be implemented so that I can structure the menu with anything else than the unordered/ordered list?

答案1

得分: 1

你可以使用此函数。这会添加<a>标签。

$navItems = array(
  'container'       => false,
  'echo'            => false,
  'items_wrap'      => '%3$s',
  'depth'           => 0,
);

echo "<nav>";
echo strip_tags(wp_nav_menu($navItems), '<a>');
echo "</nav>";
英文:

You can use this function. This adds &lt;a&gt; tag.

$navItems = array(
  &#39;container&#39;       =&gt; false,
  &#39;echo&#39;            =&gt; false,
  &#39;items_wrap&#39;      =&gt; &#39;%3$s&#39;,
  &#39;depth&#39;           =&gt; 0,
);

echo &quot;&lt;nav&gt;&quot;;
echo strip_tags(wp_nav_menu($navItems), &#39;&lt;a&gt;&#39;);
echo &quot;&lt;/nav&gt;&quot;;

huangapple
  • 本文由 发表于 2023年4月17日 22:00:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035995.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定