dongliu1883 2019-04-20 03:23
浏览 75
已采纳

使用短代码在Wordpress中加载两个单独的菜单

Currently using this code in my Wordpress menu system to load the menu.

    <div id='navbar' class='collapse navbar-collapse'>
<?php if ( function_exists('max_mega_menu_is_enabled') && max_mega_menu_is_enabled('primary') ) : ?>
    <?php wp_nav_menu( array( 'theme_location' => 'primary') ); ?>
    <?php else: ?> 
    <?php
    if ( has_nav_menu( 'primary' ) ) :
    wp_nav_menu( array(

    'theme_location' => 'primary',
    'container'      => false,
    'menu_class'     => 'main-navigation',
    'walker'         => new Aria_Walker_Nav_Menu(),
    'items_wrap'     => '<ul id="%1$s" class="%2$s" role="menubar">%3$s</ul>',
    ) ); 
    endif;
    ?>
    <?php endif; ?> 

    </div>

I am also using a plugin that allows me to switch out content based on location of the user using a shortcode.

Here is the short code

    <?php echo do_shortcode("[CBC show='y' country='us'] Content to switch out goes here [/CBC]

I've also created a menu called 'services' aside from the 'primary' one. I've tried to implement the do_shortcode method to attempt to switch out the lines that have 'primary' for 'services' but keep getting errors.

I'm not sure if I'm having syntax errors or if it isn't possible.

I've successfully used the do_shortcode method in our footer like this to swap out sticky mobile buttons and it works:

    <?php echo do_shortcode("[CBC show='y' country='us'] <a class='call-now' id='track-calls' href='tel:555-555-5555'><i class='fa fa-mobile'></i> CALL US</a>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='us'] <a class='schedule-now' id='book-now' href='http://example.com'><i class='fa fa-calendar'></i> BOOK NOW</a>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='tt'] <a class='call-now' id='track-calls' href='tel:555-555-1234'><i class='fa fa-mobile'></i> CALL US</a>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='tt'] <a class='schedule-now' id='book-now' href='http://example.com'><i class='fa fa-calendar'></i> BOOK NOW</a>[/CBC]"); ?>
  • 写回答

1条回答 默认 最新

  • dongyi6183 2019-04-22 02:34
    关注

    I was able to find a solution. I used the class option in the Wordpress menu and just gave each menu item I wanted to appear in the US only a class and same for Trinidad/Tobago. Then used the php do_shortcode method and used css via in the header of the website.

    Here is the code for anyone that may want to do similar in the future.

        <?php echo do_shortcode("[CBC show='y' country='us'] <style> li.trinidad { display:none; } li.usa-menu { display:inline-block; } </style>[/CBC]"); ?>
        <?php echo do_shortcode("[CBC show='y' country='tt'] <style> li.trinidad { display:inline-block; } li.usa-menu { display:none; } </style>[/CBC]"); ?>
    

    The plugin I am using for the functionality is: Custom Content by Country (from iControlWP) by One Dollar Plugin.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环
  • ¥15 ADS已经下载好了,但是DAS下载不了,一直显示这两种情况,有什么办法吗,非常急!
  • ¥100 Excel 点击发送自动跳转outlook邮件