Solved

WordPress - how to display custom menu in a theme?

Posted on 2011-02-18
8
1,173 Views
Last Modified: 2012-05-11
Hi,
I'm using WordPress 3.0.5, I added a menu called "Top Menu" through WP-Admin-> Appearance->Menus
I added some pages to it, how can I display it in the header of my theme? Is there any function to call such custom menus?

Thanks
0
Comment
Question by:rajoo_sharma
  • 4
  • 4
8 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 34928435
If the WP Nav Menu is active in your current theme, just add this to your header.php file where you want the menu:
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

Open in new window


If it isn't activated try adding this just before the closing ?> PHP tag in the functions.php file along with the code above for the header.php:
add_theme_support( 'menus' );

Open in new window

0
 

Author Comment

by:rajoo_sharma
ID: 34931894
Hi,
Thanks for the reply. I'm new to WordPress so my queries could be really stupid :)

1. I've two custom menus "Top Menu" and "Bottom Menu"
2. I added the following code in the header.php
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

Open in new window

3. It always shows me the Top Menu, how can I get a menu by name or ID?
4. Adding or removing this piece of code
add_theme_support( 'menus' );

Open in new window

at the end of the functions.php makes no difference. The menu always appears.

Regards
0
 
LVL 23

Accepted Solution

by:
jeremyjared74 earned 500 total points
ID: 34931955
I am not sure what you have going on in your menu's. Beside the spot where you add a custom menu it should say something like your theme supports 1 or 2 custom menu's or your theme doesn't currently support custom menus. If it says it supports 2 then you will have to find where the call to the nav menu is.

If your theme doesn't support custom menu's then add this code for up to three custom menu's:

CODE FOR FUNCTIONS.php:
add_action( 'init', 'register_my_menus' );

function register_my_menus() {
	register_nav_menus(
		array(
			'primary-menu' => __( 'Primary Menu' ),
			'secondary-menu' => __( 'Secondary Menu' ),
			'tertiary-menu' => __( 'Tertiary Menu' )
		)
	);
}

Open in new window


Then add this to the header:
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>

Open in new window


And this to the footer.php or wherever you want it:
<?php wp_nav_menu( array( 'theme_location' => 'secondary-menu' ) ); ?>

Open in new window


Then use this one in the sidebar.php for a sidebar menu:
<?php wp_nav_menu( array( 'theme_location' => 'tertiary-menu' ) ); ?>

Open in new window

0
 

Author Comment

by:rajoo_sharma
ID: 34932007
Hi,

Thanks for such a great detailed explanation. I could achieve what I wanted.

I've one more query related to displaying select Page's/Post's teaser in a block using admin. How can I accomplish this? e.g. a video on a home page or teaser of about us page on home page in a block / region.

Should I post another question for this?

Regards
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:jeremyjared74
ID: 34932147
You could use the featured image feature to achieve this. Here is a link to a good source. Let me know if you have any questions.

http://ponderwell.net/2011/02/wordpress-featured-images-and-custom-thumbnail-sizes/
0
 

Author Comment

by:rajoo_sharma
ID: 34932244
Thanks again,
I'll surely post questions as I've just started using WordPress :).

Regards
0
 

Author Closing Comment

by:rajoo_sharma
ID: 34932269
Thank you for such an accurate solution.
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 34932297
You're welcome. Let me know if you run into any problems with the featured image hack.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now