Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WordPress - how to display custom menu in a theme?

Posted on 2011-02-18
8
Medium Priority
?
1,223 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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!

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This article discusses how to create an extensible mechanism for linked drop downs.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
Suggested Courses

926 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