How to create and display a menu in WordPress is easy with the wp_nav_menu function. Navigation Bars Using CSS


In the blog article before last, I wrote about interesting innovations latest version WordPress is a special mechanism for creating and managing . Now it has become much more convenient and easier ordinary users create menus of varying complexity, which can consist not only of pages or blog categories, but also have links to any URL. To display the menu in the template, a special function wp_nav_menu is used - I’ll tell you about it today.

If in WordPress admin there is no menu section, it can be activated by adding special code to the functions.php file

Here first is the name of the menu we created. This is the use of a function in the general case without widgets; you will need to work with them a little differently there. However, the wp_nav_menu function can be output without arguments, as a result of which different situations will be “looked through” - first, a match by menu name, if at least one menu item is specified for it, otherwise a non-empty menu will simply be displayed, etc. . But again, I advise you to simply use the code above and not figure out what the function without arguments should output. Its syntax is as follows:

The following parameters are used here:

$menu - the selected identifier for the menu - ID, slug or menu name.

$container - The default UL menu is "wrapped" in a DIV container using this setting.

$container_class - indicates the class of the container, by default its value is menu-(menu slug)-container, that is, in our case, for example, the class will be menu-first-container.

$container_id - you can add an ID to the container, not specified by default.

$menu_class is the class for the UL menu element, its value is menu.

$menu_id — ID for the ul element, defaults to menu-(slug)

$echo - if you do not want to display the menu, but return the value of the function, use 0 for this setting.

$fallback_cb - if the menu does not exist, the wp_page_menu function is called.

$before - sets the text that is displayed before link A.

$link_before — displays the phrase before the link text, not specified.

$link_after — displayed after the link text, also empty.

$depth - sets the number of hierarchy levels to display the menu; the default value of 0 displays the entire menu.

$walker - some kind of incomprehensible custom “walker object”, probably more needed by advanced developers.

$theme_location - The location of the theme where the menu will be used must be activated via register_nav_menu() in order for the user to be able to select it. Also some kind of not entirely clear setting, apparently, when working with widgets.

Examples of using the wp_nav_menu function

The simplest code given in the code is:

Removing the DIV container from the menu

In principle, there is nothing complicated in creating and managing wordpress menu 3.0 no. The developers have significantly simplified the work procedure and expanded the capabilities of this element navigation. The solution is often used in a variety of template tasks, for example, when creating for mobile and desktop versions. A little later I will add a couple more snippets on the topic.

P.S. Guard. Interesting and useful for webmasters SEO blog, where you will find answers to your SEO questions.
The Aweb company has long established itself very well in the field of website promotion, optimization and search engine promotion in the Internet.

We invite you to familiarize yourself with new technology on creating a responsive (adaptive) menu without using Javascript. It uses clean and semantic HTML5 markup. The menu can be aligned left, center, or right. This menu switches on hover, which is more convenient for users. It also has an indicator that shows the “running/threading” menu item. It works on all mobile and desktop browsers including Internet Explorer!

Target

The purpose of this lesson is to show you how to regular menu make a drop-down menu on a small display.

This trick will be more useful for navigation with a lot of links, like in the screenshot below. You can condense all the buttons into an elegant dropdown menu.

Nav HTML markup

Here is the markup for navigation. The tag is required to create a drop-down menu with CSS property absolute position. We'll explain this in a lesson later. The .current class points to the active/current menu links.

  • Portfolio
  • Illustration
  • Web Design
  • Print Media
  • Graphic Design

The CSS for navigation (desktop view) is pretty basic, so we're not going to go into too much detail here. Note that we specified display:inline-block instead of float:left in the element's NAV

  • . This will allow the menu buttons to align left, center, or right by specifying text-align to




  • 

    2024 gtavrl.ru.