Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1115572

    lkd
    Participant

    hello
    i was searching for a way to add a classic menu to topbar.
    A menu that i can create from Appearance > Menu

    i found this forum post but after trying it, it was not working, and as i see it was s bit old (from 2014), i would like to ask if you have a cleaner new way of doing this?

    i have my child theme ready to roll!!

    Thanks for all!

    #1115616

    Rahul
    Moderator

    Hey There,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – WordPress Admin username / password

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thanks.

    #1115762

    lkd
    Participant

    here is the topic i was talking about

    https://community.theme.co/forums/topic/topbar-menus/

    #1115818

    Rahul
    Moderator

    Hey There,

    In the latest version of the X theme you can find the _topbar.php file in x/framework/views/global/ directory. You can get it from there. Give it a try and let us know how it goes.

    #1116249

    lkd
    Participant

    Hello,
    I tried but did not worked

    #1116716

    Friech
    Moderator

    Hi There,

    On your child theme navigate to this directory: \x-child\framework\views\global\ from there create a file named _topbar.php and paste the code below on it.

    <?php
    
    // =============================================================================
    // VIEWS/GLOBAL/_TOPBAR.PHP
    // -----------------------------------------------------------------------------
    // Includes topbar output.
    // =============================================================================
    
    ?>
    
    <?php if ( x_get_option( 'x_topbar_display' ) == '1' ) : ?>
    
      <div class="x-topbar">
        <div class="x-topbar-inner x-container max width">
          <?php if ( x_get_option( 'x_topbar_content' ) != '' ) : ?>
          <p class="p-info"><?php echo x_get_option( 'x_topbar_content' ); ?></p>
          <?php wp_nav_menu( array( 'theme_location' => 'topbar-menu' ) ); ?>
          <?php endif; ?>
          <?php x_social_global(); ?>
        </div>
      </div>
    
    <?php endif; ?>

    Then add this code on your child theme’s functions.php file.

    /*REGISTER A NEW MENU*/
    function register_my_menu() {
      register_nav_menu('topbar-menu',__( 'Topbar Menu' ));
    }
    add_action( 'init', 'register_my_menu' );

    After doing this you should get a new location for menu under Appearance > Menus > Manage Locations.

    Then style the menu with this Custom CSS on your Customizer.

    
    .x-topbar .menu li {
        display: inline-block;
        padding: 15px;
    }

    Further customizations from here would be getting into custom development, which is outside the scope of support we can offer. If you need more in depth changes, you may wish to consult with a developer. X is quite extensible with child themes, so there are plenty of possibilities.

    Hope it helps, Cheers!

    #1117086

    lkd
    Participant

    hello
    I have followed all steps but still not able to see a new location for menu under Appearance > Menus > Manage Locations.

    #1117150

    lkd
    Participant

    can you help solve this?

    #1117210

    Friech
    Moderator

    Hi There,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1117290

    lkd
    Participant

    Oh Sorry!!

    Sorry! Your code IS working!!

    there was an error on my side: i didn’t activated the child theme… the main theme was still running

    so it is ok!!! Thnaks a lot

    by the way, any css hints or style copy you have at hand that will give a real menu feelling to that new menu? or to apply the same current x theme menu styling to it?

    #1117320

    lkd
    Participant

    I was thinking about a simpler way to do this.

    Instead of adding a menu to the topbar, can i add php code into topbar content?? i mean is there a way to enable topbar content from customizer to accept php code??
    or if no way, where can i add my php code that will be rendered in topbar?

    in fact i just wan to display some links in topbar depending on user been logged in or logged out, like this:

    Logged out visitors will see:
    Welcome Visitor | Login | Join

    Logged IN users will see:
    Welcome Username | Logout | My Account

    #1117365

    lkd
    Participant

    i think i am in the way finding how to do it
    First step; copied _topbar from \x\framework\views\global\ to \x-child\framework\views\global\

    then find the code
    <?php echo x_get_option( 'x_topbar_content' ); ?>
    and replace it with

    <?php
    if ( is_user_logged_in() ) { ?>
        <a href="<?php echo wp_logout_url( get_permalink() ); ?>">Logout</a> | <a class"#" href="#">another link if you need</a>
    	<?php
    } else { ?>
        <a class="loginmodal" href="#">Log In</a>
       <?php
    };
    #1117367

    lkd
    Participant

    in my case i am calling a convertplug modal that contains itself an ultimate member shortocde

    still working on it… wil update as soon i got some cool result

    #1117482

    Rahul
    Moderator

    That’s great!

    Thanks for your support and research. Appreciated!

    If you have anything else, let us know. We’d be happy to assist you with everything.

    #1119269

    lkd
    Participant

    Hello all,
    I finally got it working as i wanted. Here are all the steps.
    Set up your child theme before:

    From front End
    1- Goto Customizer > Header > enable Topbar
    2- enter some dummy text in Topbar Content

    Backend dirty job..do it carefully
    3- copy the _topbar.php file from \x\framework\views\global\ to \x-child\framework\views\global\
    4- Open this file from your cpanel editor…Or any other mean you want wordpress theme editor could also handle this.
    5- in this _topbar.php file, search for: <?php echo x_get_option( 'x_topbar_content' ); ?> and replace it with

    if ( is_user_logged_in() ) { ?>
        Welcome <?php $current_user = wp_get_current_user(); echo $current_user->display_name; ?>, | <a href="<?php echo wp_logout_url( get_permalink() ); ?>">Logout</a> | <a href="http://www.yoursite.com/my-account">My Account</a>
    	<?php
    } else { ?>
        Welcome Visitor<a href="<?php echo wp_login_url(get_permalink()); ?>">Login or Join</a>
       <?php
    }; ?>

    Take care to replace http://www.yoursite.com/my-account with your custom url