Including the abstraction layer in other stock themes
Video: Including the abstraction layer in other stock themesAt the very beginning of this course I mentioned that if you add custom post type and custom taxonomies to your functions .php file, they follow with the theme. That also means if they're not included in the new theme you choose to activate, they won't show up, which is why we created the abstraction layer in the very beginning of the course. Moving the functions for the custom post types and custom taxonomies out of the functions.php file and into separate file it could reference. So how do you use the abstraction layer in a different theme? The same way you did for this theme. Let's see how that's done.
- Next steps
Viewers: in countries Watching now:
Learn how to build an advanced portfolio site that showcases various types of content using the free open-source application WordPress. Author Morten Rand-Hendriksen demonstrates creating custom post types, differentiating and classifying content with custom taxonomies, and working with custom post templates. The course also shows how to embed YouTube videos, build index pages, display the latest posts from different custom post types, and hook custom post types into separate themes. Exercise files accompany with the course.
- Exploring online portfolios
- Creating the site architecture
- Incorporating advanced custom post type functionalities
- Hooking a custom taxonomy to a post type
- Understanding how hierarchy relates to taxonomies
- Populating content into custom post types
- Handling multiple post type templates
- Displaying a list of links to the latest custom post type posts
- Building static pages for the front and the blog
- Creating a contact page with a contact form
Including the abstraction layer in other stock themes
At the very beginning of this course I mentioned that if you add custom post type and custom taxonomies to your functions .php file, they follow with the theme. That also means if they're not included in the new theme you choose to activate, they won't show up, which is why we created the abstraction layer in the very beginning of the course. Moving the functions for the custom post types and custom taxonomies out of the functions.php file and into separate file it could reference. So how do you use the abstraction layer in a different theme? The same way you did for this theme. Let's see how that's done.
I'll go to my Dashboard and find a new theme. So I'll go to Appearance then select Themes and from here I can click Install Themes to find a new theme to install. So I've already found a theme that you might find interesting to work with because you're making a portfolio and it's called Showcase, so we'll search for that and here it is. It's at very beginning. So we'll click Install to install the theme and Install Now and WordPress now installs the theme for me. Now I can activate this theme and you'll notice what happens. Pay to attention to the sidebar here.
With a new theme activated you see we're now back to the default Post, Media, but all our Recipes, Photos, and Videos are gone. That's because this theme does not have the reference to our post types file. So what I'm going to do now is create a new child theme. I'll refresh my themes folder so I can see the new theme. Here it is, Showcase, and now I can create a new child theme to go with showcase. The reason why I'm creating a child theme rather than altering the parent theme is because if the new update of Showcase becomes available and I upgrade Showcase from within WordPress any change I make to Showcase will be gone, because it'll be overwritten by the new update. Whereas if I create a child theme that child theme will exist even if Showcase is updated.
So I'll create a new folder, call it something like myShowcase, and within that folder I'll first create a new CSS file called style.css, and then within this file, after deleting all the content, I'll place that code that defines this as a new child theme of Showcase. So I'll go to the code snippets and here under 10.01, you'll find all the code necessary, so I'll copy it and pasted in. Here you see it says, import url ParentThemeFolder/Style. I made this generic, so you can do it with any theme.
So here I'm just going to insert the name of the parent theme folder, which is showcase and then I'll give it a new name, so I'll call it New Showcase Child Theme, and I could give it a description if I wanted to. I should always put in the author and reference the original author. And finally down here my template, I put in the parent theme folder again, so showcase. This, if you remember, is what defines what the parents theme is.
When I'll save this and go back to WordPress Admin and reload the themes page, the new child theme appears. Here it is, New Showcase Child Theme, and I can activate it. We still don't have the custom post types on the side here, but if I reload the homepage, you'll see we have a new theme applied. Now I'm going to includes the custom post type as well. So I'll go back to my code editor and under the myShowcase folder, I'll create a new file, this time a PHP file, and I'll call the functions.php and within the function.php file all I need to do is reference this post types file.
So I'll go back to my code snippets, find that code, includes_once(ABSPATH . 'wp-content/themes/posttypes, paste it in and end my PHP delimiter, save it and when I go back to my Admin panel and reload it, we now have Recipes, Photos and Videos, just like before. And if we go check inside them, you'll see that all my content is also still there. So it didn't disappear.
It just was hidden. If I now go to my front page I can visit Recipes and Photos and Videos and see the content. Now of course because this is a new theme I'm working with, I still have to make all those other changes. Like for instance I have to make a new index page so it doesn't say from the blog, but says recipes and I have to go through the same process that we've gone through with twentyeleven. But the core items, the custom post types and custom taxonomies, are on the site now and we can work in our new child theme to make this site look exactly the way we want it to.
The reason why I chose this showcase theme as the new parent theme is because it has a lot of cool features that you might want to use when you create your online portfolio. So I suggest if you have completed this course using twentyeleven and you've tested all the features in twentyeleven and you're not fully satisfied with the design, you might want to take a look at this theme instead and do the process again using Showcase instead. Of course as you have seen, in addition to adding the abstraction later to your functions.php file, you need to do a bit more work to display the content properly.
Most notably, you should always create custom post type templates for single view and index pages and also make a taxonomy.php file. With this in mind, I made all the code examples in this course generic, so you can copy them out of the text file and paste them into the theme to make them work. Just remember that if you create your own custom post types and custom taxonomies, you have to change the names in the code snippets for them to work.
There are currently no FAQs about Create an Online Portfolio with WordPress.