Hello
I have purchased the Sterling WP theme a few days ago. I wonder how to build two (2) main navigations with different menues, thus exchanging each other when clicking the respective link in the top toolbar. E.g. I wish to address content to two specific visitor groups in the same homepage (customers on the one hand, suppliers on the other hand). Thus, the starting homepage would be ‘for customers’ and display a standard main navigation with several customer specific menue items. In the top toolbar, there would be amongst others a ‘for suppliers’ link. Clicking this link would replace the afore-mentioned standard main navigation (at its same place on the web site) with a second standard main navigation with different (or some identical) menue items (compared to the starting homepage). While displaying the ‘for suppliers’ homepage, the ‘for suppliers’ link must change to ‘for customers’ in order to get the visitor back to where he came from. Enclosed please find a PDF with images of the different navigation layouts. How can this be implemented? Many thanks in advance.
Rene
Dbranes answers:
hi, there might be few possibilities, fx:
1) you could create a new page like
example.com/suppliers/
and copy the frontpage code into a custom page template,
then edit that code to add a new menu reference in wp_nav_menu()
2) use a multisite install where one site is for suppliers and one for customers
3) use a GET variable like
example.com/?suppliers
to check which menu to display.
4) try to find some clever preg_replaces on the frontpage html output for the supplier-page by using output buffers etc
ps: but it looks like there is no easy way around this ;-)
... well the quick and dirty way would be to copy the html source code from the frontpage, edit it by hand, and use it as a static page for example.com/suppliers/ ;-)
ps: I assume that both frontpage versions (customer/suppliers) are viewable by everybody
Arnav Joy answers:
using following function in functions.php you can register menus
register_nav_menu( 'menu_customers', 'Menu Customers ' );
register_nav_menu( 'menu_supplier', 'Menu Supplier' );
using wp_nav_menu() you can display the menu
see for more
http://codex.wordpress.org/Function_Reference/wp_nav_menu
I do not know how you are creating two different types of user in your site if they are based on login and logout then you can use following
if( is_user_logged_in() ) {
wp_nav_menu(array('menu' => 'menu_supplier'));
} else {
wp_nav_menu(array('menu' => 'menu_customers'));
}
let me know if you need any help
daas answers:
here's my idea. It is using cookies to define is user customer or supplier. You have to place it in the functions.php file, and edit variables containing menu slugs. Function custom_display_menu_slug
returns slug of proper menu
Feel free to contact me if you have any questions.
# change to menu slugs
$top_menu_ID = 'my_top_menu_ID';
$for_customers_ID = 'my_customers_menu_ID';
$for_suppliers_ID = 'my_suppliers_menu_ID';
add_filter( 'wp_nav_menu_items', 'custom_add_link', 10, 2 );
# add link to top menu
function custom_add_link( $items, $args )
{
global $top_menu_ID;
# check if it is top menu
if( $args->theme_location == $top_menu_ID ):
# check cookie. If 'custom_is_customer' cookie is set to true, add 'for suppliers' link (currernt user is customer)
if( isset( $_COOKIE[ 'custom_is_customer' ] ) and $_COOKIE[ 'custom_is_customer' ] == true )
# add 'for suppliers' link
$items .= '<li class="menu-item"><a href="' . home_url('/?customer=false') . '">' . __( 'For suppliers' ) . '</a></li>';
else
# add 'for customers' link
$items .= '<li class="menu-item"><a href="' . home_url('/?customer=true') . '">' . __( 'For customers' ) . '</a></li>';
endif;
# return items
return $items;
}
add_action( 'init', 'custom_set_cookie' );
# if there is given 'customer' get variable in page url, set cookie
function custom_set_cookie()
{
# set customer variable
if( isset( $_GET['customer'] ) )
if( $_GET['customer'] === '1' or $_GET['customer'] === '0' )
$customer = (bool) $_GET['customer'];
# if $customer is a bool
if ( is_bool( $customer ) === true ):
# set cookie for 3 days
setcookie( 'custom_is_customer', $customer, time() + ( 60*60*24*3 ), '/');
endif;
}
# function gives slug of proper menu, which can be used via wp_nav_menu function ( http://codex.wordpress.org/Function_Reference/wp_nav_menu )
function custom_display_menu_slug()
{
global $for_customers_ID,$for_suppliers_ID;
if( isset( $_COOKIE[ 'custom_is_customer' ] ) and $_COOKIE[ 'custom_is_customer' ] == true )
return $for_customers_ID;
else
return $for_suppliers_ID;
}