PHP in Header for Menu

Community Forums Forums Design Tips and Tricks PHP in Header for Menu

This topic is: not resolved

Tagged: , ,

This topic contains 10 replies, has 2 voices, and was last updated by  Jon Schroeder 5 months, 3 weeks ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #110974

    boldplan
    Participant
    Post count: 51

    Right now I have an alternative for the main menu for Magazine. While I’d like to use the WordPress nav menu system, unfortunately Magazine contains a number of impracticalities, primarily the second menu. (I don’t know why both weren’t bootstrap or a pure css dropdown instead of a messy menu. I have now a CSS menu that works for my entire site, including the non-Wordpress portions, and I was hoping to use it instead of the current top navigation. It works with php include statement. While this was easy with standard wordpress templates I’m unsure how one would do this with the Genesis system, to put the php include for the menu at the top, below the body tag for Magazine (or any Genesis template for that matter.) Thanks for any help or pointing me to how this is done, which I couldn’t find.

    #110982

    Jon Schroeder
    Member
    Post count: 29

    The Genesis Visual Hook plugin may help you to see which hook you’d want to use, but it’ll be something like this in your functions.php file:

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    // your php code here… e.g. include()…

    ?>
    <!– or your markup here –>
    <?php
    }

    #110983

    boldplan
    Participant
    Post count: 51

    John – Thanks – unfortunately it’s not working. Is the above code correct? I see an end php tag as well as an empty open. I’m not sure why the following would be necessary to close and open and seems unnecessary. I am guessing it is there to add markup in case I’d want between the PHP open and close tags – which is very helpful. Unfortunately I don’t see the topnav.php file being executed and appearing in that top navigation spot. It’s just a file with markup to be included as a top nav.

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    include (‘/home/mysite/public_html/menu/topnav.php’);
    }

    #110990

    Jon Schroeder
    Member
    Post count: 29

    Try echoing something instead of including the file. I have a feeling that’s the issue. Once you’ve done that, you could put whatever you like in the function (perhaps the contents of the file), and then just call the function wherever else you want to add it.

    #110993

    boldplan
    Participant
    Post count: 51

    Jon – Thanks and good idea. I tried the following but don’t see the text echoed to the screen either from the PHP or the HTML markup on the Magazine Pro theme. Theoretically it should work on any Genesis theme.

    // Add TOP NAV DROPDOWN MENU

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    echo “your php code here”;

    ?>
    <h3>or your markup here</h3>
    <?php
    }

    #110996

    Jon Schroeder
    Member
    Post count: 29

    So if the include isn’t the problem, then something else is. Make sure you’re editing the child theme’s functions.php file, first of all, and install the visual hooks plugin.

    #111015

    boldplan
    Participant
    Post count: 51

    Thanks for the help, truly. It’s definitely the right child theme as screwing it up once confirmed with a nice white screen and error. :) I even tried putting it in different places using the Visual Hook Guide and the text just doesn’t seem to appear, even in the source code. It’s why I’m asking the question here. From what I can see, this should do the trick, as is. Maybe I’m missing something. Maybe one of the parameters is incorrect? This is what frustrates me with Genesis themes – the incredibly simple becomes an exercise in backending your way into a theme.

    // Add TOP NAV DROPDOWN MENU

    add_action( ‘genesis_before_content’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    echo “Please work testing code!”;

    ?>
    <h3>Please work testing code!</h3>
    <?php
    }

    #111018

    Jon Schroeder
    Member
    Post count: 29

    Huh. Everything looks right here to me, with the possible exception of the quote marks, if you copied and pasted directly.

    I’ll take another look at this with fresh eyes tomorrow.

    #111128

    boldplan
    Participant
    Post count: 51

    I tried a fresh install of the Magazine theme. I used the above code and pasted it into the functions.php at the bottom to make sure it was the last function processed. Didn’t matter where I put it – the code never echoed to the screen, neither the PHP nor the HTML. I told you, replacing the top nav with my own was not easy! :/

    add_action( ‘genesis_header’, ‘yourprefix_add_secondary_menu’, 20 );
    function yourprefix_add_secondary_menu() {
    echo “BLAH BLAH BLAH”;

    ?>
    or your markup here
    <?php
    }

    #111709

    boldplan
    Participant
    Post count: 51

    Finally got it to work. I had to put it after header I believe. I used Simple Genesis Hooks plugin – something like that – and then was able to infer what needed to be done in function form. For some reason, using what appears to be almost identical code (changing the function) and putting it in the right hook did the job. Thanks for the help along the way.

    #111782

    Jon Schroeder
    Member
    Post count: 29

    Glad to hear that; the function name shouldn’t matter, so I’m sure we were using the wrong hook is what happened. What was the right one?

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.