Solved

WordPress - how to display custom menu in a theme?

Posted on 2011-02-18
8
1,192 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
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress  featured images 3 16
str_replace not working in php script 4 25
Finding the source of a shortcode 2 23
MySql and Apache/PHP Error Reporting 2 25
In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

816 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

11 Experts available now in Live!

Get 1:1 Help Now