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 WordPress Theme Development Custom Post Type Templates in WordPress The Portfolio Homepage

Leigh Maher
Leigh Maher
21,830 Points

Why use plugins and then create custom files?

Earlier in this course Zac mentions that we use the plugins for custom posts because if someone updates their theme they will no longer be able to access the custom content. However, here we are creating custom files for the theme, so it seems we're using a blend of plugins and customization. Does this not negate the argument for using plugins in the first place? And why, if we go to the trouble of creating custom pages i.e. the portfolio.php pages, do need to use plugins anyway?

4 Answers

Craig Watson
Craig Watson
27,930 Points

Ahh i understand a little better what you are asking now Leigh :)

What you are saying is correct If you have create a theme yourself with "page-portfolio.php" to control how your portfolio pieces are displayed and then you choose to change theme your custom content will now not be displayed.

However that custom content is kept as changing the theme does not erase the plugins, this is the benefit to the plugin approach. Swapping themes may not display your custom content initially, but you have still kept that custom content and you can simply add the necessary file to your child theme to have it displayed as you wish.

If you hard code the functionality of that plugin into your theme it will be stored in the theme folder and not the plugin folder in your wp_content directory. Hence when you change the theme that data goes with it but as mentioned if you use a plugin you can swap between themes day by day and not loose the content :)

Hope this helps

Craig

Craig Watson
Craig Watson
27,930 Points

Hi Leigh :)

I'm not sure if I'm reading your question correctly but here goes at an explanation....

When you use the plugins i.e. Custom Post Type UI / Advanced Custom Fields these are helping you control your custom content form the admin area like add, remove, edit and so on...

Your portfolio.php or my-dogs.php or jobs.php are all to do with controlling the way that content from the admin area is then displayed through the browser.

So you use the plugins to help create the content and post types

Then the php files control how they look and are looped through

The naming convention of the files is may be what is throwing you off at this point so I would say once you get to the template hierarchy course all will seem more solid! :)

Hope this helps!

Craig

Leigh Maher
Leigh Maher
21,830 Points

Hi Craig,

Thanks for your reply.

He says if you update the theme you wouldn't be able to access that info. I understand this. However, if you change to a new theme, you will no longer have access to the e.g. page-portfolio.php or any other custom php page you've created? Isn't that right?

So, by the logic he uses about not being able to access the content in a new theme, wouldn't you need to apply that same logic to all the theme files?

So, what I'm saying is if there is any customization to the theme whether it's to a php template or hard coding the functionality of the plugins he's used (presumably using additional custom php templates), if you change to a new theme all this customization will be lost. I just think this renders his initial reasoning redundant for using the plugins instead of custom hard coding it into the theme.

Leigh

Leigh Maher
Leigh Maher
21,830 Points

Got it. Thanks Craig.