Wordpress menu with pages and category option

Asked

Viewed 715 times

-1

I’m learning to make Wordpress themes and seeing tutorials how to make call menus in Wordpress.

I saw several tutorials on how to call category menu and pages, but I’m not finding a tutorial on how to create a menu that calls both, because I see many sites that have this option.

Is there any tutorial on how to do this? I’m starting in the construction of themes, but I’ve been running Wordpress sites for some time.

  • Better than asking for suggestions for tutorials -Google is an expert on this- is to show your code and what your problem with it. The specialty of this site are programmers solving programming problems.

  • I already solved, it’s okay. I’ll post the code here.

2 answers

1

The best way to work with menus in Wordpress themes is by using the native function, in time it is no longer necessary to use type functions

wp_list_categories()

for the menus, so come on.

First you need to enable menu support in your theme, so enter the code below in the functions.php of your theme:

if (function_exists('add_theme_support')) { add_theme_support('top'); add_theme_support('footer'); }

Done this in your theme you will use the codes below to display the menus where you wish:

wp_nav_menu( array('menu' => 'topo' ) );
wp_nav_menu( array('menu' => 'rodape' ) );

Now just go to the menu Appearance > Menus on the administrative page of your theme, click on create new menu, then you will select top or footer and choose which pages and categories should be part of the menu. In practice it’s very simple.

1

Thank you Leo, I will study this method tbm.

I saw on Codex this way

in functions I put like this:

if ( function_exists( 'register_nav_menus' ) ) {
register_nav_menus(
array(
'header-menu' => 'top menu',
)
);
}

and on pages like this.

<nav id="menu">
        <?php
        wp_nav_menu(array(
        'theme_location' => 'header-menu', // aqi vc seleciona o menu que vc registrou
        'container' => 'nav',
        'container_id' => 'nav',
        'container_class' => 'nav-teste',
        'menu_id' => 'menu',
        'menu_class' => 'menu',
        'echo' => true,
        'before' => '',
        'after' => '',
        'link_before' => '',
        'link_after' => '',
        'depth' => '0',
        ));
        ?>
    </nav>

Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.