我正在工作,我的自定义wordpress主题,我有困难,设计第一个菜单在标题中,我想要的方式。
因此,在header.php中,我以这种方式插入菜单,这样链接就不会被表标记包围:
<?php
$menuParameters = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);
$output = strip_tags(wp_nav_menu($menuParameters), '<a>');
//This is my first try with regex, but i didnt manage to
//only insert the character in between two links and not
//one at the and as well.
//$output = Preg_replace( "(\n)", "$0|\r\n", $output);
echo $output;
?>因此,这段代码给了我一个菜单,如下所示:
<a href="http://localhost/page-1/">Page 1</a>
<a href="http://localhost/page-2/">Page 2</a>
<a href="http://localhost/page-3/">Page 3</a>
<a href="http://localhost/page-4/">Page 4</a>
<a href="http://localhost/page-5/">Page 5</a>为了理解,这就是我想得到的输出:
<a href="http://localhost/page-1/">Page 1</a>
|
<a href="http://localhost/page-2/">Page 2</a>
|
<a href="http://localhost/page-3/">Page 3</a>
|
<a href="http://localhost/page-4/">Page 4</a>
|
<a href="http://localhost/page-5/">Page 5</a>谢谢你提前给我答案!
发布于 2018-09-15 11:11:20
wp_nav_menu()允许参数after和link_after在链接文本或链接标记之后添加文本,以便更新参数:
$menuParameters = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
'after' => "<span>|</span>"
);编辑:如果您不想在最后一个链接之后显示一个分隔符,您可以使用一些CSS伪元素:
.mymenu span:last-child{ display: none; }发布于 2018-09-15 09:49:14
<a href="http://localhost/page-1/">Page 1</a><a href="http://localhost/page-2/">Page 2</a><a href="http://localhost/page-3/">Page 3</a><a href="http://localhost/page-4/">Page 4</a><a href="http://localhost/page-5/">Page 5</a>https://stackoverflow.com/questions/52343254
复制相似问题