【问题】
由于不小心,把之前wordpress中retina的主题更新成最新的0.2版本了,导致原先我手动在0.1的基础上修改的很多代码,使得支持多个菜单,prev和next post,帖子的已读次数等,都丢失了。
所以很是悲剧。然后现在只好一点点手动去重新改写对应的代码,以添加对应的功能。
【解决过程】
下面记录折腾的过程。
1.先是用FileZilla 3.5.3去下载下来对应的retina\lib\structure\menu.php,然后用notepad++打开,结果显示有点问题,每一行都多了一个换行的效果,所以很是悲催。
先不管了,手动删除多余空行,接着按照之前的记忆,去修改对应的代码,改好后,再上传到服务器上,替换原先的menu.php。结果重新打开www.crifan.com,网站却无法显示了,显示500错误。看来是代码添加的有问题了。
2.后来只好去retina的官方网站上面,下载最新的源码,然后找到对应的menu.php,再重新替换回来,然后网站才能正常打开。
3.后来再次重新用notepad++打开menu.php,结果显示又正常了,没了多余的换行了。
然后接着修改代码,去参考这里:
http://www.dayunet.com/WordPress-method-multiple-custom-menu.html
修改后的代码menu.php为:
<?php /** This theme uses wp_nav_menu() in two locations.*/ register_nav_menus( array( 'primary-menu' => 'Primary Menu', 'second-menu' => 'Second Menu', ) ); /** * Primary Menu */ /** Primary Menu Callback */ function retina_primary_menu_cb() { wp_page_menu (); } /** Build Primary Menu */ function retina_primary_menu() { echo '<div class="menu1"> <div class="menu1-data">'; if ( has_nav_menu( 'primary-menu' ) ): $args = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'primary-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args2 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'second-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); wp_nav_menu( $args ); wp_nav_menu( $args2 ); else: retina_primary_menu_cb(); endif; echo '<div class="clear"></div> </div> <!-- end .menu1-data --> </div> <!-- end .menu1 -->'; } /** Primary Menu Init */ add_action( 'retina_after_header', 'retina_primary_menu_init' ); function retina_primary_menu_init() { retina_primary_menu(); } ?>
然后登陆网站后台管理界面,就可以看到对应的显示效果了:
然后就照葫芦画瓢,去添加更多的菜单项。
然后又一共添加了9个,登陆后台管理页面,刷新后,效果如下:
最后共添加了所需要的12个,相关代码如下:
register_nav_menus( array( 'primary-menu' => 'Primary Menu', 'second-menu' => 'Second Menu', 'third-menu' => 'Third Menu', 'fourth-menu' => 'Fourth Menu', 'fifth-menu' => 'Fifth Menu', 'sixth-menu' => 'Sixth Menu', 'seventh-menu' => 'Seventh Menu', 'eighth-menu' => 'Eighth Menu', 'nighth-menu' => 'Nighth Menu', 'tenth-menu' => 'Tenth Menu', 'eleventh-menu' => 'Eleventh Menu', 'twelveth-menu' => 'Twelveth Menu', ) );
和
if ( has_nav_menu( 'primary-menu' ) ): $args = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'primary-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args2 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'second-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args3 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'third-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args4 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'fourth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args5 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'fifth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args6 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'sixth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args7 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'seventh-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args8 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'eighth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args9 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'nighth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args10 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'tenth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args11 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'eleventh-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); $args12 = array( 'container' => 'div', 'container_class' => 'primary-container', 'theme_location' => 'twelveth-menu', 'menu_class' => 'sf-menu1', 'depth' => 0, 'fallback_cb' => 'retina_primary_menu_cb' ); wp_nav_menu( $args ); wp_nav_menu( $args2 ); wp_nav_menu( $args3 ); wp_nav_menu( $args4 ); wp_nav_menu( $args5 ); wp_nav_menu( $args6 ); wp_nav_menu( $args7 ); wp_nav_menu( $args8 ); wp_nav_menu( $args9 ); wp_nav_menu( $args10 ); wp_nav_menu( $args11 ); wp_nav_menu( $args12 );
这12个全部建立好后,把之前就已经存在的菜单(这个是之前就自己建立好的,和主题是脱离的,所以没被覆盖掉),设置好对应关系,
再打开主页,就可以看到主页中的菜单显示效果就是所想要的12个了:
转载请注明:在路上 » 【已解决】wordpress中给Retina主题添加多个菜单