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

Ken Stone
Ken Stone
29,703 Points

Can I create a WordPress widget and have it appear only at the top of certain pages?

Can I create a WordPress widget and have it appear only at the top of certain pages? I want it on the frong page, and pages with IDs equal to 489, 494, etc... The widget will be a text/html widget a form that submits a date and to check my availability.

Maybe I should create a page template for the pages that I want to display this on top then use that template instead of the default page.php template for those pages. I'm using the Twenty Fourteen theme.

If I create a cal-page.php what will happen when the theme updates?

Assuming I create the new template and put a function in functions.php again my question is what will happen if Twenty Fourteen updates?

Should I create a child theme?

3 Answers

Kevin Korte
Kevin Korte
28,149 Points

You would need to use a child theme for sure. If you make any modifications to an existing theme, those changes will be gone the next time the theme is updated.

Wordpress gives you function to check which page template you're using, and you could use that to check if you are on the right template to show your widget.

Ken Stone
Ken Stone
29,703 Points

If I make a child theme will the child theme receive any of the updates that happen to the parent?

Or is it just up to me to port in any updates ?

Kevin Korte
Kevin Korte
28,149 Points

The child theme piggybacks on the parent theme, meaning whatever is missing from the child theme to be considered a complete theme, it will fallback on the parent theme.

The entire parent theme will update, but of course any part of the theme you override with a child theme won't matter, any parts you don't override, you'll have the benefit of the update in your child theme.

Ken Stone
Ken Stone
29,703 Points

Thanks Kevin,

Yes I just did it. It's all clear to me now. I went through the course and did the examples on a test site but after doing it on a real existing site that matters it's really all coming together now.

Now I just need to create a filter function to add my content to the top of the post as opposed to the top of the page as is it now by just calling the function from the top of the loop.

You can see it now at http://djkenstone.com

Not sure I'll have time to create the filter today but should be done by tomorrow.

Thanks again, Ken

Kevin Korte
Kevin Korte
28,149 Points

Awesome! I just checked it out. It looks like you're off to a great start. Good luck in your endeavours, let me know how it goes!

Ken Stone
Ken Stone
29,703 Points

I just added the filter to add the date checker to the top of the post. Only problem now is I'm getting it at the top of every post and I only want it on the page-mobiledj.php template.

Fixed with: if(is_page_template('page-mobiledj.php')){}