WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Same question - trouble with code input (22 posts)

  1. jgoldberg2013
    Member
    Posted 9 months ago #

    Responsive Theme with child theme. http://www.help-alliance.de
    Level of PHP is zero.
    I have tried a number of times to insert the code provided into various placs but I keep getting a parse error.
    Code inserted is if ( function_exists ( 'the_msls' ) ) the_msls()
    you mention place this in functions.php.
    There are two functions.php files.
    1 in main dir of theme - code is.

    * WARNING: Please do not edit this file in any way
     *
     * load the theme function files
     */
    require ( get_template_directory() . '/includes/functions.php' );
    require ( get_template_directory() . '/includes/theme-options.php' );
    require ( get_template_directory() . '/includes/post-custom-meta.php' );
    require ( get_template_directory() . '/includes/tha-theme-hooks.php' );
    require ( get_template_directory() . '/includes/hooks.php' );
    require ( get_template_directory() . '/includes/version.php' );

    2 in functions.php in theme dir/includes - code relating to main-nav is `/**

    * This feature enables custom-menus support for a theme.
             * @see http://codex.wordpress.org/Function_Reference/register_nav_menus
             */
            register_nav_menus(array(
    			'top-menu'         => __('Top Menu', 'responsive'),
    	        'header-menu'      => __('Header Menu', 'responsive'),
    	        'sub-header-menu'  => __('Sub-Header Menu', 'responsive'),
    			'footer-menu'      => __('Footer Menu', 'responsive')
    		    )
    	    );
    
    		if ( function_exists('get_custom_header')) {

    Alternative is the header.php file but I still cant get the flags to show in the menu bar itself..
    This is the header.php code:

    <?php get_sidebar('top'); ?>
    				<?php wp_nav_menu(array(
    				    'container'       => 'div',
    						'container_class'	=> 'main-nav',
    						'fallback_cb'	  =>  'responsive_fallback_menu',
    						'theme_location'  => 'header-menu')
    													);
    						?>

    I have spent a few hours on this trying to figure this out without support but I feel I am out of league when php coding is at work.

    http://wordpress.org/extend/plugins/multisite-language-switcher/

  2. Same question - trouble with code input

    Sorry, what are you trying to accomplish? "Same question" isn't very descriptive.

  3. jgoldberg2013
    Member
    Posted 9 months ago #

    Sorry Jan.
    I hve read alot of the feeds regarding to try and get the multisite language swtcher in my main navigation bar.
    The plugin provides widget that sits ontop of nav bar and all the advise I have tried to follow had not helped me.

    the plug in site oes give advise to how to do this but I am very confused as to where and how to insert this to acheive my goal.
    their support link is https://github.com/lloc/Multisite-Language-Switcher/wiki.
    My details are above for your veiwing.
    I really do hope you can help, this is the last step in my website. Thansk in advance for any guidance.

  4. jgoldberg2013
    Member
    Posted 9 months ago #

    also to add - this is a post that the theme support provides to get a thier serch widget in the main nav area.
    Copy header.php from Responsive to Responsive Child Theme and add this in:

    <div id="search-box">
                <?php get_search_form(); ?>
            </div><!-- end of #search-box -->

    I thought I could just replace theirs with the code the language swtcher provided but keep getting parse errors.

  5. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    There is a brief description here:

    https://github.com/lloc/Multisite-Language-Switcher/wiki/Generate-the-output#manipulate-the-navigation-menu

    It seems that you should use the second functions.php when you want to insert some code. The menu in your header.php has the theme_location header-menu. So I would use something like this

    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'header-menu' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );

    Hope this helps.

    Cheers,
    Dennis.

  6. Sorry Jan.

    Nothing to be sorry for. ;)

    I hve read alot of the feeds regarding to try and get the multisite language swtcher in my main navigation bar.

    That's better.

    You do have a multisite installation right?

    Try creating a child theme and modify your child theme's copy of the header.php file and put these lines in it.

    <!-- Multisite Language Switcher START -->
    <?php if ( function_exists( 'the_msls' ) ) the_msls(); ?>
    <!-- Multisite Language Switcher END -->

    Then load up your web site and view the HTML. At a minimum you should see those comments in the HTML. This will let you test if the function the_msls() is even active or not.

  7. jgoldberg2013
    Member
    Posted 9 months ago #

    Hi Dennis - thanks for quick response. Very impressed with plug in and now your support.
    I have read the link a number of times now but still not having any luck - I keep getting a parse error on the lines I dumped in.

    You mention both the functions.php and the header.php
    Which one do I place your code into - this is what is confusing.
    I have placed your code as above in the 2nd functions.php loacted in theme/includes/...
    This is the code but it did nothing to the site. http://help-alliance.de

    * This feature enables custom-menus support for a theme.
             * @see http://codex.wordpress.org/Function_Reference/register_nav_menus
             */
            register_nav_menus(array(
    			'top-menu'         => __('Top Menu', 'responsive'),
    	        'header-menu'      => __('Header Menu', 'responsive'),
    	        'sub-header-menu'  => __('Sub-Header Menu', 'responsive'),
    			'footer-menu'      => __('Footer Menu', 'responsive')
    		    )
    	    );
    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'header-menu' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '
    <li>' . implode( '</li>
    <li>', $arr ) . '</li>
    ';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );
    
    		if ( function_exists('get_custom_header')) {</a>

    [Please post code & markup between backticks or use the code button. Your posted code has now been permanently damaged by the forum's parser.]

  8. jgoldberg2013
    Member
    Posted 9 months ago #

    Jan- yes multisite is set-up and the plugin is active and working. That is not the issue - The plugin author has stepped (as above) in to assist kindly so thanks for your advise though.

  9. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    Just add the code to the second functions.php and it will add your flags automatically to the menu.

  10. jgoldberg2013
    Member
    Posted 9 months ago #

    I dumped your code into 2nd functions.php file adsaved it in my child theme directory.
    This is what comes back to me when going to URL.
    Fatal error: Cannot redeclare responsive_get_options() (previously declared in /homepages/29/d125184200/htdocs/en/wp-content/themes/coinlogistics_child/functions.php:38) in /homepages/29/d125184200/htdocs/en/wp-content/themes/responsive/includes/functions.php on line 43

    ------------------------------------------------------------
    If I save the edited file in the theme/includes directory then nothing happens.
    -----------------------------------------------------------
    I placed the code as so:

    /**
     * Set a fallback menu that will show a home link.
     */
    
    function responsive_fallback_menu() {
    	$args = array(
    		'depth'       => 0,
    		'sort_column' => 'menu_order, post_title',
    		'menu_class'  => 'menu',
    		'include'     => '',
    		'exclude'     => '',
    		'echo'        => false,
    		'show_home'   => false,
    		'link_before' => '',
    		'link_after'  => ''
    	);
    	$pages = wp_page_menu( $args );
    	$prepend = '<div class="main-nav">';
    	$append = '</div>';
    	$output = $prepend.$pages.$append;
    	echo $output;
    }
    
    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'header-menu' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );
    /**
     * This function removes .menu class from custom menus
     * in widgets only and fallback's on default widget lists
     * and assigns new unique class called .menu-widget
     *
     * Marko Heijnen Contribution
     *
     */
    class responsive_widget_menu_class {
    	public function __construct() {
  11. jgoldberg2013
    Member
    Posted 9 months ago #

    OK - thought I had a light bulb moment and removed the MLS widget out and - ALL gone now. no flags at all.

  12. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    Please use just my code:

    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'header-menu' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );

    You copied other code too. responsive_get_options() for example...

  13. jgoldberg2013
    Member
    Posted 9 months ago #

    I placed your code EXACTLY at the END of the functions.php file
    in the theme/includes folder.
    AND NOTHING changed. do I need to edit your code in anay way?
    Do I remove your widget from the dashboard from all sites on network?
    I am really stuck here- I do hope we can sort this out.
    These are the last lines on the funcion.php file.

    }
    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'header-menu' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );
    add_filter( 'body_class','responsive_add_class' );
    ?>
  14. jgoldberg2013
    Member
    Posted 9 months ago #

    I even tried your code in the header.php at the end of the page but still nothing changes.
    I have really run out of options and is frustrated as this seems very easy to implemnt but after hours of trying - I am only failing.

  15. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    My code can just work if you place it in the functions.php and not in the header.php. You should check if header-menu is the right menu or if you have to use another menu like top-menu, sub-header-menu (or footer-menu)...

  16. jgoldberg2013
    Member
    Posted 9 months ago #

    Hi Dennis, thanks for being so patient with me but I still can not get switcher in the main-nav.
    I have done exactly what you have asked.
    I have tried it with the switcher widget placed in a widget area
    AND with it out of any widget area.
    Either way still nothing.
    I know the "main"nav is the class as it says so in firebug html.
    snapshot of info can be seen at http://postimg.org/image/8fv8f1zp3/
    I know zero about php so I am really stuck if you say that your code MUST work and it does not.

  17. jgoldberg2013
    Member
    Posted 9 months ago #

    OK - I hve actually ditched this process and took a completely different angle. Working with margins.

    #header #mslswidget-4 {
      clear: right; float: right;
      margin-bottom:-45px; width: 300px;

    Although it is not embeded it works for now until we can fugure why your code does not work in my theme.

  18. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    OK, very good.

    The snapshot is quite interesting. Does that mean that there is no menu defined and it shows a fallback-menu?

  19. jgoldberg2013
    Member
    Posted 9 months ago #

    Sorry but I do not understand what you are saying. I am pretty new to the coding stuff.
    What do think the issue was - as you state that my scenario is quite interesting.
    On a another note: Now that I am using margins to move the widget box over my nav bar - for some reason it does not show in IE9 but is fine in FF.
    When using float to right the images disapear - they are there in F12 development tool but no image is shown.
    When settings are :

    #header #mslswidget-4 {
      margin-bottom:-45px;
      display: inline-block;
      float: none;
     }

    then the flags show but are behind the nav bar - reied making z-index 9999 but still did not help.
    Any advise as all reading ppoints to widget code not being compatible with floats.

  20. jgoldberg2013
    Member
    Posted 9 months ago #

    As soon as I use float - the flag images go behind the nav bar.
    As mentioned they are there according to dev tools. But in Firefox - the images are perfect - infront of nav bar.

  21. jgoldberg2013
    Member
    Posted 9 months ago #

    For anybody else trying to do this, I have created a new post with the short-end of process and result.

  22. jgoldberg2013
    Member
    Posted 9 months ago #

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.