Links on Menu?

In order to use the directory plugin, I needed to create an entire WP install just for this plugin. I did so, at http://searchenginemarketing.net/directory

All works well with this setup, however, I need to be able to direct users to the main website, via the
navigation menu on this new directory site.

The only way to do so, currently, is to create a page, and offer a link on this page for users to click on, in order to get back to the main site. (that's how I'm accommodating this issue now -- but it's sloppy)

See an example here: http://searchenginemarketing.net and http:searchenginemarketing.net/directory

Again: If you're on http://searchenginemarketing.net/directory (the install of WP exclusively created for the directory plugin) I'd like to allow users to click on a link in the main navigation bar that will take them to my main site, which is http://searchenginemarketing.net

Thanks!

Todd

  • Timothy Bowers

    You created a new site? or a sub blog of the main site?

    Well what I would do is either:-

    1. If the theme permits you could use a custom menu. Located in the admin of that site under Appearance -> Menu.

    2. Edit the themes code to put in what you require.

    Looking in the code of the theme for directory its located in:

    /directory/themes/default/includes/components/navigation.php

    It uses the function wp_page_menu() so it order the pages. I have in the past included a link in the title so

    <a href="link" title="title name">Link Name</a>

    And that works but perhaps not the best thing.

    Not sure about your main site theme though as I'm not familiar with that.

    You could also use the wp_nav_menu() function to add the Menu options under Appearance -> Menus.

    Hope this helps. :slight_smile:

  • Timothy Bowers

    I edited my post because I inadvertently deleted some of the original on the first edit. :-s

    Anyway, to follow on, in the file mentioned:

    /directory/themes/default/includes/components/navigation.php

    <div id="navigation-wrapper">
    <div id="navigation"><!-- start .navigation -->
    	 <?php //$options = get_site_option('dp_options'); ?>
         <?php wp_page_menu( array( 'sort_column' => 'menu_order, post_title', 'menu_class' => 'menu-header', 'include' => '', 'exclude'=> ( isset( $options['submit_page_id'] ) ) ? $options['submit_page_id'] : NULL, 'echo' => true, 'show_home' => true,'link_before' => '','link_after' => '' )); ?>
    </div><!-- end .navigation -->
    </div>

    You could just add the html anchor there? So it would look like this:

    <div id="navigation-wrapper">
    <div id="navigation"><!-- start .navigation -->
         <?php //$options = get_site_option('dp_options'); ?>
         <a href="http://link" title="title name">Main Site Home</a>
         <?php wp_page_menu( array( 'sort_column' => 'menu_order, post_title', 'menu_class' => 'menu-header', 'include' => '', 'exclude'=> ( isset( $options['submit_page_id'] ) ) ? $options['submit_page_id'] : NULL, 'echo' => true, 'show_home' => true,'link_before' => '','link_after' => '' )); ?>
    </div><!-- end .navigation -->
    </div>
  • toddfarmer

    Thanks for the help - you rock!

    It works, and gets the job done.

    Thanks again!

    I have one remaining challenge, though -- and since you're such a ninja and figured things out so far, I will at least ask the question...

    As you can see here http://searchenginemarketing.net/directory

    ...the new "main home link" I implemented (based on your added line of code in the navigation.php file) puts the new "main home link" on the normal navigation bar -- which is great.

    However, the navigation bar that is rendered next, is put on a second line and looks a little funky.

    I'm hoping to put them all on the top line. Thus, the plugin's rendered navigation items will go directly to the left of the hard coded "main home link", and not on a second line. (Also, all the links would be left-justified.)

    Any suggestions or thoughts here?

    Thanks again!

    Todd

  • Timothy Bowers

    Thanks for the help - you rock!
    It works, and gets the job done.
    Thanks again!

    You are very welcome!

    However, the navigation bar that is rendered next, is put on a second line and looks a little funky.

    I didn't see that happening, but I really like the affect to be honest with a little more styling.

    OK.... so two choice, we figure out how to append a link to the wp_page_menu() or we swop it for the WP inbuilt menu system......... *Cue Dramatic Music* :wink:

    We'll do the first one now and then the second one in case:

    <div id="navigation-wrapper">
    <div id="navigation"><!-- start .navigation -->
    	 <?php //$options = get_site_option('dp_options');
    	function extra_page_menu_link($extralink) {
    		$extralink .= '<li><a href="http://domain.com/">Your Site</a></li>';
    		return $extralink;
    	}
    	add_filter('wp_list_pages', 'extra_page_menu_link');
    ?>
         <?php wp_page_menu( array( 'sort_column' => 'menu_order, post_title', 'menu_class' => 'menu-header', 'include' => '', 'exclude'=> ( isset( $options['submit_page_id'] ) ) ? $options['submit_page_id'] : NULL, 'echo' => true, 'show_home' => true,'link_before' => '','link_after' => '' )); ?>
    </div><!-- end .navigation -->
    </div>

    But perhaps you just want to make it easier to control the menu system, so lets replace the above function to allow you to use WordPress in built menu system:

    By default if there is no menu selected it will fall back to the pages navigation and so we should perhaps do some checks?

    <div id="navigation-wrapper">
    <div id="navigation"><!-- start .navigation -->
    <?php
    $wpNavMenu = wp_nav_menu;
    if (!empty($wpNavMenu)) {
        	 wp_nav_menu( array( 'theme_location' => 'main_header', 'menu_class' => 'menu-header' ) );
    } else {
     	wp_page_menu( array( 'sort_column' => 'menu_order, post_title', 'menu_class' => 'menu-header', 'include' => '', 'exclude'=> ( isset( $options['submit_page_id'] ) ) ? $options['submit_page_id'] : NULL, 'echo' => true, 'show_home' => true,'link_before' => '','link_after' => '' ));
    } ?>
    </div><!-- end .navigation -->
    </div>

    You also need to open up:

    /wp-content/themes/default/includes/core/theme-core.php

    Around line 43 you will see:

    register_nav_menus( array(
                'primary' => __( 'Primary Navigation', 'directory' ),
            ) );

    Change that to:

    register_nav_menus( array(
                'primary' => __( 'Primary Navigation', 'directory' ),
            	'main_header' => __( 'Main Header'),
            ) );

    You can then assign the position from the WordPress Menu Area.

    But............ Lets say you wanted a different menu for logged in users and logged out user:

    Back to the navigation.php file:

    <div id="navigation-wrapper">
    <div id="navigation"><!-- start .navigation -->
    <?php 
    
    $wpNavMenu = wp_nav_menu;
    if (!empty($wpNavMenu)) {
    	 if ( is_user_logged_in() ) {
        	 wp_nav_menu( array( 'theme_location' => 'logged_in', 'menu_class' => 'menu-header' ) );
    	} else {
        	 wp_nav_menu( array( 'theme_location' => 'logged_out', 'menu_class' => 'menu-header' ) );
    	}
    } else {
     	wp_page_menu( array( 'sort_column' => 'menu_order, post_title', 'menu_class' => 'menu-header', 'include' => '', 'exclude'=> ( isset( $options['submit_page_id'] ) ) ? $options['submit_page_id'] : NULL, 'echo' => true, 'show_home' => true,'link_before' => '','link_after' => '' ));
    } ?>
    </div><!-- end .navigation -->
    </div>

    And then in the /wp-content/themes/default/includes/core/theme-core.php

    Change those lines to:

    register_nav_menus( array(
                'primary' => __( 'Primary Navigation', 'directory' ),
                 'logged_in' => __( 'Logged In'),
    	     'logged_out' => __('Logged Out'),
            ) );

    Does this cover all bases this time? :wink:

    I just hope this post renders correctly. lol

    I partially tested this as I went along, but not extensively! :wink:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.