dropdown-menu-widget-thumb

Dropdown Menu – PHP Template Tag Usage Explained

on July 31, 2011 | 29,872 views

Dropdown menu widget is so easy to use as a widget, but it also supports usage of PHP template tags. Using PHP code to insert the menu, you can easily add menus to your theme as many times as you like. In this post i will give you different code snippets to add the widget to your theme.


Default usage

Adding dropdown menu widget using php is so easy. If you are going to add just one menu, things get a lot easier. All you have to do is to insert:

<?php shailan_dropdown_menu( ); ?>

somewhere in your header.php template. This is the default usage. This template tag uses settings page to get the necessary information. So after you add this code, you can easily change your menu options in the Dropdown Menu Widget options page.


Adding pages menu

To add a dropdown menu of your pages, you can use:

<?php shailan_dropdown_menu( array( 'menu' => 'pages' ) ); ?>

code. This snippet will get all the other data from the template tag options page except the menu type.


Adding categories menu

To add categories dropdown, you can use:

<?php shailan_dropdown_menu( array( 'menu' => 'categories' ) ); ?>

code. This snippet will also get all the other data from the template tag options page except the menu type.


Adding a custom menu using php code

To add a custom menu you created you need to set menu variable to either its ID or its name. Here are some examples:

<?php shailan_dropdown_menu( array('menu'=>'Katalog') ); // Adds a custom menu named Katalog ?>

<?php shailan_dropdown_menu( array('menu'=>'439') ); // Adds a custom menu with id 438 ?>

You can add as many as you like. There is no limit on the number of menus you can add.


Full arguments template

If those are not enough for your requirements here is the full arguments list. You can create many different menus using this argument template. Just change the variables as you need:

<?php // SETUP
$args =array(
	'menu' => 'pages',			// Menu type pages | categories | menuID | menu name
	'exclude' => '21,35,438',	// IDs of pages to be excluded
	'login' => true,			// Display login/logout link?
	'admin' => false,			// Show site admin link?
	'vertical' => false,		// Display vertical?
	'home' => true,				// Display home link?
	'align' => 'right',			// Align left | center | right
	'width' => '500'			// Width of menu
);
// CREATE
shailan_dropdown_menu( $args ); ?>

Conclusion

Dropdown menu widget allows you to easily manage your menus. It automatically generates menu code, effects and even CSS styles. All you need is to add it and then edit your menu as you like. Using template tag’s powers, now you can add multiple dropdown menus to your site, even if you don’t have any sidebars. Here i showed you most common uses of the template tag. I hope you found it useful.

NOTE: If you have any ideas, any points that need improvements, please leave your comment below.

ADVERTISEMENT
ADVERTISEMENT

About Shailan.com Staff

Shailan.com is a design blog about WordPress and web design. We regularly write about wordpress, plugins, themes, web design resources, php, css, jquery, adsense and more.. If you want to get notified about our posts, be sure to subscribe to our feed or follow us on facebook.

Share Your Thoughts

Your email address will not be published.

12 thoughts on “Dropdown Menu – PHP Template Tag Usage Explained”

  1. MAria says:

    I can’t seem to get the z-index to work with my menu it is dropping down below either the footer or banner, wonder if you have any thoughts

    I love this plugin

  2. Julia says:

    Is it possible to change z-index of dropdown menus?

    I have 2 horizontal navs, and the top nav dropdowns are hidden behind the second nav below it.

  3. wait…this is the right thread! :D
    Is this plug still supported?
    Is there anywhere else I can out the tag so it will work?

  4. I can get the code to integrate into the navigation. Depending on where in the header I am putting it…something happens…such as a second plain text menu that has the animated dropdown menus, but it will not integrate with my top menu. I am using the Avada theme and the latest version of WordPress

  5. Jim says:

    Hi,

    When I put this into a div in a page template, the width parameter doesn’t work.

    ‘Tour’, // Menu type pages | categories | menuID | menu name
    ‘exclude’ => ”, // IDs of pages to be excluded
    ‘login’ => false, // Display login/logout link?
    ‘admin’ => false, // Show site admin link?
    ‘vertical’ => false, // Display vertical?
    ‘home’ => false, // Display home link?
    ‘align’ => ‘right’, // Align left | center | right
    ‘width’ => ‘200’ // Width of menu
    );
    // CREATE
    shailan_dropdown_menu( $args ); ?>

    I tested some ‘align’ valus, and they are fine.

    Thanks,

    Jim

  6. Ben says:

    I’ve noticed that since I upgraded WP to 3.3 the drop downs don’t work anymore. I’m not sure if this has anything to do with your plug in (as I’m afraid to upgrade any of the other sites I’ve used this on until I know what the issue is for sure) but I figured I’d start here. :)

    Thanks for the awesome plugin. :)

  7. Louis says:

    Amazing plugin, just testing it, will report later, so far it looks awesome. Thanks!