2 Hauptnavigationen in einer Wordpress Installation

  • Hallo Zusammen,

    ich habe ein Problem mit meiner Main Navigation. Ich verwende das Theme Sydney und habe die Hauptnavigation so eingestellt wenn man auf einen Link klickt, fährt die Frontpage zu entsprechender stellen nach unten. Dort kann man bei entsprechendem Thema auf weiter klicken bzw. auf mehr erfahren. Dann wird man zu entsprechender Seite weiter geleitet.

    Klickt man dann aber auf der Unterseite wieder auf einen Link in der Main Navigation kommt man da nicht mehr hin, da die Navigation in Design->Menü über Links mit #pg-209-1 usw. aufgebaut ist. Das ist mir auch alles klar.

    So was ich aber nun gerne hätte ist eine if else Bedingung bei der ich für meine Frontpage/ Hauptseite eine andere Main Navigation anzeigen lassen kann wie für alle anderen Seiten. Wichtig dabei ist mir das ich nicht ein zweites zusätzliches Menü über eine Sidebar anzeigen lassen möchte.

    Kann mir da jemand sagen ob das 1. so funktioniert wie ich mir das vorstelle und 2. was ich da genau tun müsste?

    Ich bin für alle Hinweise und tips sehr dankbar.:)

    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

  • Das geht ganz einfach.

    Ich würde es so machen. zwei Naviagtionen erstellen und dann mit php if abfragen.

    if frontpage dann soll die navigation a und wenn nicht frontpage dann navigation b.


    if ( is_front_page() && is_home() ) {
    navigation a
    } else {
    navigation b
    }
    der php stimmt jetzt nicht aber so geht es aufjedenfall ;) ob jetzt if home oder if frontpage .. da habe ich keine ahnung.

    leg zwei navigationen an und dann einmal die eine ausgeben und wenn nicht die andere. normal if else abfrage


    Du könntest es mit Conditional-Tags versuchen: https://codex.wordpress.org/Conditional_Tags
    z.B. mit if(is_page()) https://codex.wordpress.org/Conditio...gs#A_PAGE_Page

  • Hi! Erstmal Danke für deine Antwort.
    So habe ich auch gedacht, mit einer if Abfrage, funktioniert aber nicht.
    Ich glaube aber inzwischen, dass es nicht an der if Abfrage liegt sonder daran, dass ich meine frontpage bzw. homepage nicht ansprechen kann.
    Denn es gibt hinter meiner Domain keinen slug etc. also es kommt lediglich http://www.domain.com/
    Wenn ich auf Seite bearbeiten gehe dann sehe ich in der Adresszeile nocht das .../post=209&action=edit ... also dachte ich normal ist ja 209 die ID aber die spricht es auch nicht an. Inzwischen bin ich richtig verzweifelt.

    Mit folgenden Codes hab ich es schon probiert:
    Conditional Tag
    function.php

    [COLOR=#0000BB][FONT=monospace]<?php
    [/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// Add a extra menus
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]register_nav_menus[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( array(
    [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'primary' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Erstes Menü'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'mytheme' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]),
    [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'secondary' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Zweites Menü'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'mytheme'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
    ) );
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>


    [/FONT][/COLOR]header.php

    [COLOR=#0000BB][FONT=monospace]<?php
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]if ( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]is_page[/FONT][/COLOR][COLOR=#007700][FONT=monospace](array( [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Mypage1'[/FONT][/COLOR][COLOR=#007700][FONT=monospace],[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Mypage3'[/FONT][/COLOR][COLOR=#007700][FONT=monospace],[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Mypage2' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]) ) ) { [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]<!-- Begin primary menu #menu1 -->[/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]<div id="menu1" role="navigation">[/FONT][/COLOR]
    [COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// This is where the menu is added
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]wp_nav_menu[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'container_class' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'menu-top'[/FONT][/COLOR][COLOR=#007700][FONT=monospace],
    [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'theme_location' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'primary'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'fallback_cb' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]''[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) ); [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]</div><!-- end of #menu1 -->[/FONT][/COLOR]
    [COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]} [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>


    [/FONT][/COLOR]Und dann habe ich noch die Möglichkeit über einen Filter versucht mit folgendem Code (ist aber nur ein Beispiel)

    function change_wp_nav_menu_args($args = '')
    {
    $pageID = get_the_id();
    if($pageID == '52') //custom menu for site with id 52
    {
    $args['menu'] = 'impressum-menu';
    }
    return $args;
    }
    add_filter( 'wp_nav_menu_args', 'change_wp_nav_menu_args' );

    Die page-id habe ich wieder mit 209 angegeben, bei $args['menu'] = habe ich mein in der functions.php angelegtes 2. Menü eingegeben.
    Ging aber auch nicht. Vielleicht fällt dir oder auch anderen noch eine Idee ein.

  • Für eine statische Startseite ist is_front_page() und für die Blog Startseite ist is_home() zuständig.

    [size=10]Bitte immer zuerst die Forensuche nutzen und erst danach Deine Fragen hier im Forum stellen, denn sehr vieles wurde schon mehrfach beantwortet. Bitte dabei auch die Forenregeln beachten.
    Kein Support per PN - Fragen gehören ins Forum.[/SIZE]
    [size=8]Wenn du eine weise Antwort verlangst, musst du vernünftig fragen. (Johann Wolfgang von Goethe)[/SIZE]

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!