Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Make a Website with WordPress Customizing WordPress Themes Customizing WordPress Theme Files

Gabriel Ward
Gabriel Ward
20,222 Points

Adding a navigation menu that shows/disappears on the click of an icon.

There is a menu button at the top of the page.

When it is clicked a search bar appears. How would I add a new button to the home page, and then a custom navigation menu with links to the different categories on my website? One that shows/hides when it the button is clicked. Would I need to add some jQuery somewhere?

2 Answers

Hi Gabriel,

You would need to enqueue a JavaScript file and make sure that it has noconflict wrappers.

After setting up the button in your HTML you could then use something like the jQuery toggle to make it show and hide on click.

Hope that helps give you an idea.

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Rich,

Where would I include the html? In one of the .php files?

Cheers

Gabe

Hi Gabriel,

It really depends on where you'd like it to show but I tend to include them in the header.php file and fix it to the top of the page so it shows constantly when a user is scrolling on mobile.

Hope that helps

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Do you think it'd help for me to take some basic PHP courses, and read some tutorials on PHP?

I think it may be a good idea, but I also think trying to spread myself too thinly across languages might not be good.

Hi Gabriel,

I think it would be good if working on WordPress Theme Development to know PHP Basics. That said, if you know how to enqueue scripts, this particular issue would be HTML, CSS and JavaScript / JQuery related.

You would use HTML to create the button, CSS to style the button and menu drop down, and JQuery to show / hide it using something like toggle.

In theory the PHP would already have been used to include the navigation.

Hope that helps in some way.

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Ok, is it possible to work out how to enqueue scripts just from the codex link you've posted here? I'm definitely confident with the basics of html, CSS, and jQuery, but learning how to incorporate it all in the php Wordpress files is where I'm confused at this point.

Hi Gabriel,

Yes, the page above gives an explanation and this part in particular gives examples.

Hope that helps :)

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Rich,

I'm slowly getting my head around this enqueuing business, but I'm just wondering, where does one put the html? Is it in one the php files of the theme that is being worked with? If there's one thing I'm trying to get used to, it's that there doesn't really seem to be any plain old html files in WP themes.

Also, am I correct in thinking that to enqueue the jQuery, I would create a new js file, write the jQuery code in it, include it in my child theme folder, and then enqueue this file into the relevant php file? That's what I'm thinking after reading the functions/enqueuing code page.

Cheers,

Gabe

Hi Gabe,

In terms of enqueuing the styles and scripts try these:

If you're not already working through it, and you're aiming to build your own theme, I'd recommend following the WordPress Theme Development course in general.

In terms of adding the HTML, the same course has details on this so if you'd like to add your navigation menu to the header for example, this would probably help.

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

Ok, in your first answer above, you talk about setting up the button in HTML. So this with what you're saying here, implies that adding this sort of thing is actually more like building a theme, as opposed opposed to child theme manipulation? Child theme manipulation is just for changing layouts, not so much actually adding things?

Gabriel Ward
Gabriel Ward
20,222 Points

Ok, in your first answer above, you talk about setting up the button in HTML. So this with what you're saying here, implies that adding this sort of thing is actually more like building a theme, as opposed opposed to child theme manipulation? Child theme manipulation is just for changing layouts, not so much actually adding things?

Sorry to confuse you, I'd just assumed it was for a custom theme. This can be done with child themes too if required.

I worked through the WordPress Development track which should cover everything you need to develop a child or custom theme.

Hope that helps.

-Rich

Gabriel Ward
Gabriel Ward
20,222 Points

In any case, thank you for your help and all the links. I appreciate it.

No problem :)

Gabriel Ward
Gabriel Ward
20,222 Points

Cool, yea I'm working through the Wordpress Development track. What I'm doing is working with a child theme of this

http://demo.authenticthemes.com/apollo/

I simply want to add a sliding menu that toggles on the click of a button at the top of each page.