假设我在导航中有MyAccount和MyStats,我想在“我的”文本周围包含 标记。我如何在Wordpress中执行此操作?
例如我的众议院,我的街道。
答案 0 :(得分:1)
如果我正确理解了这个问题,你只想把“我的”这个词加粗?看一下这个屏幕截图,您应该可以将其直接发布到Nav菜单中,具体取决于您要添加的内容:
答案 1 :(得分:0)
您需要通过编辑head.php / header.php文件来实现此目的。要做到这一点,你需要做两件事之一。 FTP进入您的服务器并导航到
sitefolder/wp-content/themes/themefolder/header.php
找到导航或菜单。或者在wordpress的后端,转到
appearance->editor
在此处找到该文件并进行必要的更改。
使用此方法,您需要对菜单项进行硬编码。因此,不会对页面名称等进行任何更改。但这是最简单的方法。
答案 2 :(得分:0)
如果您想要自定义导航名称,只需创建一个自定义菜单:
答案 3 :(得分:0)
如果您使用 jQuery ,您可以执行类似的操作,以便使用<span>
元素包装每个菜单项的前两个字母。
$('li').each(function(){
$(this).html('<span>'+$(this).text().substring(0,2)+'</span>'+$(this).text().substring(2));
});
您可能需要更改选择器,或者更具体一些,以免影响您网站上的所有li
。
这是一个工作小提琴 - http://jsfiddle.net/dM5sb/
对于 PHP 解决方案,如果您当前正在使用wp_nav_menu()
,则可能需要切换到get_pages()
并执行类似的操作。
<ul>
<?php
$args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'hierarchical' => 1,
'child_of' => 0,
'parent' => -1,
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
foreach($pages as $page) {
$title = $page->post_title;
$my = substr($title, 0, 2);
$the_rest = substr($title, 2);
?>
<li><a href="<?php echo get_page_link( $page->ID ); ?>"><span><?php echo $my ?></span><?php echo $the_rest?></a></li>
<?php } ?>
</ul>
这是未经测试的,但您可以在此处详细了解wordpress get_pages()
功能 - http://codex.wordpress.org/Function_Reference/get_pages
答案 4 :(得分:0)
此链接帮助我获得了我想要的东西: How do I generate a custom menu/sub-menu system using wp_get_nav_menu_items in wordpress?
如果获得验证代码是个问题,我会把我的代码放在这里。
感谢您的回答