Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WordPress - how to display custom menu in a theme?

Posted on 2011-02-18
8
Medium Priority
?
1,220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to count occurrences of each item in an array.

719 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