本文介绍了菜单中的 Wordpress 自定义链接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用空白主题模板来创建 wordpress 主题,并通过将以下代码添加到 header.php 来启用菜单:
</nav>
我把它加到了functions.php中:
if (function_exists('register_nav_menus')) {register_nav_menus(大批('main_nav' =>'主导航菜单'));};
当我向页面添加链接时,菜单显示并且工作正常,但是当我添加自定义链接说 http://www.google.com 带有 Google 标签,导航栏中没有显示任何内容.当我查看源时,根本没有填充自定义链接.
<div class="菜单"><ul><li class="page_item page-item-9"><a href="http://localhost/wordpress/anatomy/">Anatomy</a></li><li class="page_item page-item-11"><a href="http://localhost/wordpress/history/">History</a></li><li class="page_item page-item-7"><a href="http://localhost/wordpress/home/">首页</a></li>
</nav>
我的导航 css 很简单:
nav {填充:0;保证金:0;位置:绝对;宽度:900px;}九里{列表样式:无;字体系列:'Numans',无衬线;字体大小:15px;颜色:#ffffff;文本对齐:左;文本转换:大写;填充:0;边距:0 30px;显示:内联;位置:相对;顶部:-32px;}nav ul li a {文字装饰:无;颜色:#ffffff;}nav ul li a:访问过{颜色:#ffffff;}nav ul li a:hover{颜色:#cccccc;}导航:活动{颜色:#ffffff;}
我对 php 和 wordpress 主题非常陌生,我在网上找不到任何有同样问题的人.
解决方案
问题是您的 theme_location
与您注册菜单时指定的名称不匹配.
当您注册菜单时,您将其命名为 main_nav
.既然你调用了它,为了显示那个菜单,你需要改变对菜单的调用以引用 main_nav
,像这样:
wp_nav_menu( array('theme_location' => 'main_nav') );
I am using a blank theme template to create a wordpress theme and I enabled menus by adding the below code to header.php:
<body <?php body_class(); ?>>
<div id="navbar"></div>
<div id="wrapper" class="clear">
<nav>
<?php wp_nav_menu( array('theme_location' => 'primary' ) ); ?>
</nav>
And I added this to functions.php:
if (function_exists('register_nav_menus')) {
register_nav_menus(
array(
'main_nav' => 'Main Navigation Menu'
)
);
};
The menu shows up and works fine when I add links to pages but when I add a custom link to say http://www.google.com with the label Google nothing shows up in the navigation bar. When I view the source the custom link is not being populated at all.
<nav>
<div class="menu">
<ul>
<li class="page_item page-item-9"><a href="http://localhost/wordpress/anatomy/">Anatomy</a></li>
<li class="page_item page-item-11"><a href="http://localhost/wordpress/history/">History</a></li>
<li class="page_item page-item-7"><a href="http://localhost/wordpress/home/">Home</a></li>
</ul>
</div>
</nav>
My css for the nav is simple:
nav {
padding:0;
margin:0;
position:absolute;
width: 900px;
}
nav ul li
{list-style: none;
font-family: 'Numans', sans-serif;
font-size: 15px;
color: #ffffff;
text-align:left;
text-transform: uppercase;
padding: 0;
margin: 0 30px;
display: inline;
position: relative;
top:-32px;
}
nav ul li a {
text-decoration: none;
color: #ffffff;
}
nav ul li a:visited
{color: #ffffff;
}
nav ul li a:hover
{color: #cccccc;
}
nav ul li a:active
{color: #ffffff;
}
I am very new to php and wordpress theming and I can't find anyone online with the same issue.
解决方案
The issue is that your theme_location
does not match the name you assigned when you registered the menu.
When you registered the menu, you called it main_nav
. Since you called it that, in order to display that menu, you need to change the call to the menu to reference main_nav
, like so:
wp_nav_menu( array('theme_location' => 'main_nav' ) );
这篇关于菜单中的 Wordpress 自定义链接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!