Create own footer menu in Wordpress? - php

I do have two menus in my Wordpress-Page which are called
Mainmenu(Primary Menu)
Footer
I associated the "Mainmenu" to the header of the website. I want the footer of the Wordpresspage to look exactly like the header, only difference should be the Links in it. It should not be taken from the "Mainmenu", but from the menu called "Footer". The function of the Header looks like this:
echo '<nav id="rtp-primary-menu" role="navigation" class="rtp-nav-wrapper' . apply_filters( 'rtp_mobile_nav_support', ' rtp-mobile-nav' ) . '">';
rtp_hook_begin_primary_menu();
/* Call wp_nav_menu() for Wordpress Navigaton with fallback wp_list_pages() if menu not set in admin panel */
if ( function_exists( 'wp_nav_menu' ) && has_nav_menu( 'primary' ) ) {
wp_nav_menu( array( 'container' => '', 'menu_class' => 'menu rtp-nav-container clearfix', 'menu_id' => 'rtp-nav-menu', 'theme_location' => 'primary', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
} else {
echo '<ul id="rtp-nav-menu" class="menu rtp-nav-container clearfix">';
wp_list_pages( array( 'title_li' => '', 'sort_column' => 'menu_order', 'number' => '5', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
echo '</ul>';
}
rtp_hook_end_primary_menu();
echo '</nav>';
The Theme i am using is rtPanel. Can anyone tell me how i simply can change this function in the way that it will load its content from the Menu called "Footer" and not from the Primary Menu which is "Mainmenu"?
Please dont worry about the CSS and everything, i will take care about this. I really just want to now how i have to change this function to load the "Footer"-Menu in it and not the Primary-Menu(Mainmenu).
As an Attachment how it look in the menu:
Thank you very much advance!

This is really simple, in fact when you start developing wordpress theme this might be one of the very first items you need to learn.
You need to register a menu location for footer seciton. You can learn more in codex
register_nav_menu( 'footer', __( 'Footer Menu', 'theme-slug' ) );
This will register the menu for you. Since you already have the menu location just find the location parameter. We're going to use that in the following code. For now assume it 'footer' like the above one. And the code for the footer menu according to your referenced code-
echo '<nav id="rtp-primary-menu" role="navigation" class="rtp-nav-wrapper' . apply_filters( 'rtp_mobile_nav_support', ' rtp-mobile-nav' ) . '">';
//rtp_hook_begin_primary_menu(); // we better disable this hook as it intends for the header primary menu
/* Call wp_nav_menu() for Wordpress Navigaton with fallback wp_list_pages() if menu not set in admin panel */
if ( function_exists( 'wp_nav_menu' ) ) {
wp_nav_menu( array( 'container' => '', 'menu_class' => 'menu rtp-nav-container clearfix', 'menu_id' => 'rtp-nav-menu', 'theme_location' => 'footer', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
} else {
echo '<ul id="rtp-nav-menu" class="menu rtp-nav-container clearfix">';
wp_list_pages( array( 'title_li' => '', 'sort_column' => 'menu_order', 'number' => '5', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
echo '</ul>';
}
//rtp_hook_end_primary_menu(); // we better disable this hook as it intends for the header primary menu
echo '</nav>';
Notice the theme_location parameter in wp_nav_menu() function? This is the one which plays behind to get you menu correctly.
Now play around with CSS and you might get what you intend.
Hope this might help you.

Related

wordpress custom menu with page thumbnail

I am trying to get a menu with few links, and show their/link/page featured image. following is my code for functions.php.
function register_my_menus() {
register_nav_menus(
array(
'main-menu' => __( 'Main Menu' ),
'useful-links' => __( 'Userful Links' )
)
);
}
add_action( 'init', 'register_my_menus' );
and this is where i am calling it in the page.
<?php wp_nav_menu( array( 'theme_location' => 'useful-links', 'sort_column' => 'menu_order', 'container_class' => 'useful-links', 'menu'=>'Posts Menu' ) ); ?>
i know something is missing but kindly advice. my page look and feel allow 6 links and their images.
thanks
This should be in your functions.php to register the menu within WordPress.
if (!function_exists('wp_basicTemplateSetup')) {
function wp_basicTemplateSetup() {
// Register the Main Menus into WordPress
register_nav_menus(array(
'primary' => __('Main Menu', 'theme-name'),
));
}
}
add_action('after_setup_theme', 'wp_basicTemplateSetup');
In your theme, where the menu is sitting you need to tell the menu function, which menu to look for. So..:
// Variable that tells WordPress which menu to use, look at "Theme Location"
// Put this variable either at the top of your theme, of right *before* the function wp_nav_menu
$mainmenu = array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'some-menu-css-class',
'depth' => 2
);
// The WordPress menu function
<?php wp_nav_menu($mainmenu); ?>
These 3 components are necessary to get your WordPress menu working.

Wordpress menus

i m having a problem with menus.
I had a template that wasnt originaly for WP.
so i integrated it.
when i started the site there was only one menu which works great.
i added <?php wp_nav_menu('primary'); ?> and its all ok
Now i need to add another one (custom links in the header section)
sooo i used this method
register_nav_menus( array(
'header' => 'Header menu',
'footer' => 'Footer menu'
) );
and recieved new locations for menus.
for the second menu i added
<?php wp_nav_menu( array( 'theme_location' => 'header', 'menu_class' => 'nav-menu', 'fallback_cb' => false ) ); ?>
now the problem:
there is a primary menu (it has few items)
and the custom menu ( its currently empty)
when i add new page to custom menu its being shown in both primary and custom menus.
if i delete all the items from custom menu, primary menu items are back in place...
what is the problem?
Thank you.
If I understand correctly, it looks like you are pointing to the wrong registered menu in the wp_nav_menu(). Specifically in the theme_location.
When you are building the "second menu" which is the "footer", theme_location should be footer since that is the name you gave it in the register_nav_menus().
<?php wp_nav_menu(
array( 'theme_location' => 'footer', // Change 'header' to 'footer'
'menu_class' => 'nav-menu',
'fallback_cb' => false )
);
?>

add element into the same div as primary menu LI in genesis_do_nav?

I am just starting out and have limited PHP knowledge, but I am trying to learn as fast as I can. I am working with the Genesis framework and designing a site for someone. I moved my navigation to the top of the page using remove_action & add_action. So now the genesis_do_nav loads on the genesis_header hook. But I would like to have my logo inline with the navigation bar at the top and centered. Should I add that element to the genesis_do_nav? And how would I go about that? I found the function in the menu.php so I started tinkering with it before I move it to a newly named function in my child theme, but whatever I do to the code it only seems to add it before or after the navigation and appears as an block element, I would prefer if I could get it in the same div with the primary menu li. Like I said my knowledge of PHP is limited. Please help.
add_action( 'genesis_after_header', 'genesis_do_nav' );
function genesis_do_nav() {
//* Do nothing if menu not supported
if ( ! genesis_nav_menu_supported( 'primary' ) )
return;
//* If menu is assigned to theme location, output
if ( has_nav_menu( 'primary' ) ) {
$class = 'menu genesis-nav-menu menu-primary';
if ( genesis_superfish_enabled() )
$class .= ' js-superfish';
$args = array(
'theme_location' => 'primary',
'container' => '',
'menu_class' => $class,
'echo' => 0,
);
$nav = wp_nav_menu( $args );
//* Do nothing if there is nothing to show
if ( ! $nav )
return;
$nav_markup_open = genesis_markup( array(
'html5' => '<nav %s>',
'xhtml' => '<div id="nav">',
'context' => 'nav-primary',
'echo' => false,
) );
$nav_markup_open .= genesis_structural_wrap( 'menu-primary', 'open', 0 );
$nav_markup_close = genesis_structural_wrap( 'menu-primary', 'close', 0 );
$nav_markup_close .= genesis_html5() ? '</nav>' : '</div>' ;
$nav_output = $nav_markup_open . $nav . $nav_markup_close;
echo apply_filters( 'genesis_do_nav', $nav_output, $nav, $args);
}
}
I would like it to end up inline with the primary menu LI
echo apply_filters( 'genesis_do_nav', $nav_output, $nav, $args, HTML ELEMENTS HERE?);

Changing menu <li> to <dd> with wp_nav_menu

I created a theme in HTML using Zurb Foundation and then integrated it into a WordPress theme.
The primary nav section in my theme, in its most basic form is:
<dl>
<dd></dd>
<dd></dd>
<dd></dd>
</dl>
I configured wordpress's menu call as such:
wp_nav_menu( array(
'theme_location' => 'primary',
'menu' => '',
'container' => '',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<dl id="tabnav" class="sub-nav">%3$s</dl>',
'depth' => 0,
'walker' => '') );
But in order to change the wrapping <li> that wordpress puts out to a <dd> I would need to write a custom walker.
I looked through some custom walkers and can see parts of the logic, but is creating a class every time I want to use custom html for a menu the only/most efficient way to go about it?
digwp provides an easier approach than the walker
create a function that builds the menu from scratch.
in your functions.php
// custom menu example # http://digwp.com/2011/11/html-formatting-custom-menus/
function clean_custom_menus() {
$menu_name = 'nav-primary'; // specify custom menu slug
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list = '<dl>' ."\n";
foreach ((array) $menu_items as $key => $menu_item) {
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= "\t\t\t\t\t". '<dd>'. $title .'</dd>' ."\n";
}
$menu_list .= "\t\t\t". '</dl>' ."\n";
} else {
// $menu_list = '<!-- no list defined -->';
}
echo $menu_list;
}
and to call it in your theme:
<?php if (function_exists(clean_custom_menus())) clean_custom_menus(); ?>
so you would have to edit the $menu_name to your menu slug.
here's the source

Changing Wordpress PHP to Show Different Menu to Logged In Users

I'm building a membership website on Wordpress and would like to show a different navigation menu to logged in users.
Here is the current PHP code that displays the menu :
<?php /* Our navigation menu. */ ?>
<?php if ( isset ($options['admired_remove_superfish']) && ($options['admired_remove_superfish']!="") )
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
else
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu_class' => 'sf-menu','fallback_cb' => 'admired_page_menu' ) );?>
Here's the PHP code that needs to replace that code :
<?php
if ( wp_emember_is_member_logged_in() ) {
wp_nav_menu( array( 'menu' => 'logged-in-members' ) );
} else {
wp_nav_menu( array( 'menu' => 'normal-visitor-menu' ) );
}
?>
If I just replace the old code, with the newer code it will work, but the formatting is off. I need the Superfish part in the current code, but I'm not sure how to make it work in PHP.
I know this may be a little confusing, but I would appreciate any help. Thanks!
P.S. This is a tutorial from the plugin's site. I've been following it, but I somehow need to keep the Superfish in there. I'm sure not sure how to do it.
http://www.tipsandtricks-hq.com/wordpress-membership/show-different-navigation-menu-to-your-members-and-non-members-551
The 'menu_class' => 'sf-menu' will add the sf-menu class for the menu (<ul class="sf-menu">) and super fish plugin will use this class to identify the menu and style will be applied which has been declared in the super fish plugin's css
<?php
if ( wp_emember_is_member_logged_in() ) {
wp_nav_menu( array( 'menu' => 'logged-in-members', 'menu_class' => 'sf-menu' ) );
} else {
wp_nav_menu( array( 'menu' => 'normal-visitor-menu', 'menu_class' => 'sf-menu' ) );
}
?>
For more see this.
Considering the code above, the only thing that is changing is the actual location of the menu. The (existing) code is showing that you want the menu that's in 'theme_location' => 'primary' where, as you have a hardcoded menu you want to use, and you're selecting it with 'menu' => 'loggged-in-members' The finished result will be...
<?php
if ( wp_emember_is_member_logged_in() ) {
wp_nav_menu(
array(
'container_class' => 'menu-header',
'menu' => 'logged-in-members',
'menu_class' => 'sf-menu',
'fallback_cb' => 'admired_page_menu'
)
);
} else {
wp_nav_menu( array( 'menu' => 'normal-visitor-menu' ) );
}
?>

Categories