Community Forums › Forums › Archived Forums › Design Tips and Tricks › PHP in Header for Menu
Tagged: menu, navigation, php
- This topic has 10 replies, 2 voices, and was last updated 9 years, 3 months ago by
Jon Schroeder.
-
AuthorPosts
-
June 21, 2014 at 1:04 pm #110974
boldplan
ParticipantRight 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.
June 21, 2014 at 3:57 pm #110982Jon Schroeder
MemberThe 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
}June 21, 2014 at 4:13 pm #110983boldplan
ParticipantJohn - 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');
}June 21, 2014 at 5:00 pm #110990Jon Schroeder
MemberTry 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.
June 21, 2014 at 5:38 pm #110993boldplan
ParticipantJon - 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
}June 21, 2014 at 6:33 pm #110996Jon Schroeder
MemberSo 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.
June 21, 2014 at 8:51 pm #111015boldplan
ParticipantThanks 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
}June 21, 2014 at 9:52 pm #111018Jon Schroeder
MemberHuh. 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.
June 23, 2014 at 3:26 am #111128boldplan
ParticipantI 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
}June 27, 2014 at 12:03 am #111709boldplan
ParticipantFinally 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.
June 27, 2014 at 11:06 am #111782Jon Schroeder
MemberGlad 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?
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.