← WordPress

Como mostrar Menu Wordpress em <select>?

Lida 4072 vezes

Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Boas,
Procurei bastante, mas não encontrei o que queria. Vi poucas soluções e não funcionavam.

Se alguém me puder ajudar :)
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Podes tentar por aqui: http://wordpress.stackexchange.com/questions/27497/how-to-use-wp-nav-menu-to-create-a-select-menu-dropdown
Já tinha usado isso, mas devo ter feito algo mal e não deu na altura. Agora funcionou :lol:

obrigado ;)

EDIT: Há outro pequeno problema, como se "linka"?
Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

http://www.eggplantstudios.ca/wordpress-create-a-dropdown-select-menu-with-wp_nav_menu/

Encontrei isto que parece melhor, no entanto, a parte do código para por no functions.php dá erro na linha 3. Alguém me sabe ajudar? :)
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

João, esse código alguns erros de copy/paste, vê se assim funciona:

Código: [Seleccione]
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {
 
    function start_lvl($output, $depth) {    }
 
    function end_lvl($output, $depth) {    }
 
    function start_el($output, $item, $depth, $args) {
        // Here is where we create each option.
        $item_output = '';
 
        // add spacing to the title based on the depth
        $item->title = str_repeat("", $depth * 4) . $item->title;
 
        // Get the attributes.. Though we likely don't need them for this...
        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
        $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
        $attributes .= ! empty( $item->url )        ? ' value="'   . esc_attr( $item->url        ) .'"' : '';
 
        // Add the html
        $item_output .= '<option'. $attributes .'>';
        $item_output .= apply_filters( 'the_title_attribute', $item->title );
 
        // Add this new item to the output string.
        $output .= $item_output;
 
    }
 
    function end_el($output, $item, $depth) {
        // Close the item.
        $output .= "</option>\n";
 
    }
 
}
Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Muito obrigado Ricardo! :D
O developer do blog que meti também me respondeu e corrigiu o código. Está tudo a funcionar perfeitamente :)