- This topic is empty.
June 9, 2010 at 9:48 am #29297
I was wondering if/which would be the best way to have a second header show only if users on are the index.php page? Currently I have two different divs in my header.php, the first div is the main menu bar and the second div is another menu bar. But I only want to show this second div/menubar only on the index.php.
So can I create a header2.php and do an if statement to do an include?
Or could I create a page templete or something?
Just checking which would be the best way to do this.
Thanks,JakeJune 10, 2010 at 9:24 pm #77576vincentMember
Why can’t you put whatever stuff you ONLY want to be on the index, in index.php? :D Just put it at the top before it calls the loops and stuff. You may need to leave a open div tag for some type of heading you have if you still want the index only heading to be included in it. For example:
Another way, which is probably the best, would be to use an if statement to check the is_home WordPress function. I haven’t tested this, but it should work.
Or, do you not want 2 headers to be shown on the index, but just place the normal header for the new one on the index?
Thanks for the help Vincent,
I tried doing the last example and that is want I am wanting, however it didnt work. Something with if statement was giving me an error.
Basically I have two menu bars in my header.php and the first menubar I want displayed on all pages so it works fine in the header.php.
However the second menubar in the header.php I want to be displayed on only the main home page.
Any other ideas?
Create a php file like index-header.php and put all your second index only header code in there and then go to your index.php provided by wordpress, go to the appropriate place you want the header and put <?php include_once("index-header.php") ?>
Well here is what I’ve got but its not showing the content in the index-header.php file.. Any ideas?
Well I assume you have the index.php and the index-header.php in the same folder so it’s not a file path issue. Try
And make sure everything is posted. I’ve gone through a couple problems where it took me a long time to figure out that I hadn’t even posted yet.
For some reason thats not working either, I can’t figure out why its not wanting to work. Any other ideas?
Thanks for the help,
get_header is a wordpress function – not a standard PHP function. If you are trying to use get_header outside of wordpress it will not work.
You only need the include.
Well I’ve changed it back to this, but its still not wanting to grab the contents of the index_header.php. I do have the index_header.php inside the theme folder, is that correct?
In you latest post you have it as:
It should be:
If you placed that inside the index.php inside the themes folder and inside the theme you are using, and the index_header.php is in the exact same folder, you shouldn’t have any issues. I just did this yesterday in fact so I know it works. Make sure you cleared the index_header.php file of any of the default html like the meta and the body and such and only have the header html inside.
Make sure you have everything posted as well. Sometimes while making changes on several pages, we forget to post one, and that screws things up for the rest of the files.
It cant be a file path issue because the index.php and the index_header.php should be in the exact same folder right next to each other. If it still doesn’t work, try linking to it from the root.
And if that doesn’t work, then I can’t think of anything else to do.
noahgelman that worked great, thank you.
Now that I have the include working I have one more thing to solve. I’ve done this before but not sure why its not working with wordpress.
In the very top of my index.php file I have the following code.
In my header I have the following but for some reason its not wanting to output the echo part.
This works in another site I have thats not running wordpress. Is there something I’m not doing right?
The reason I’m wanting to do this is that there is the second menu that I only want to be displayed on the main home page.
Oh, I am definitely not the person to ask on that. I’m very noobish when it comes to php.
If I had to guess. It might be something inside the wordpress code that is conflicting with it. They have a lot going on in those files to make things work. Lots of stuff it could conflict with. Someone else with more php knowledge would know better than I.
This Topic can be marked ‘Solved’
I ended up created a different page template that included the second submenu, then on the home page I just set the page template to the new one I created and now it works perfect.
I just had to think long enough to figure it out.
Thanks everyone for the help.
- The forum ‘Back End’ is closed to new topics and replies.