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.
This course revolves around using custom post types and custom taxonomies to create separate buckets for separate types of content. These custom post types and custom taxonomies are defined in the functions.php file in the theme. The functions.php file is where core theme functionality is called or created and custom post types and custom taxonomies are core theme functionalities in WordPress. The problem with using custom post types and custom taxonomies is that since they are defined in the functions file for each theme, if you switch to a different theme, the post types and taxonomies disappear.
To avoid this we will create the custom post types and custom taxonomies in a separate file. This file can then be called with an Include function from within the functions.php file in the current theme, and can also be called from any of the other themes, if you're using those instead. I like to call this an obstruction layer. The first step in this process is to create the file where we are going to put all the functions to create the custom post types and custom taxonomies. So we will do that going into themes and then I will create a new file and call it posttypes. Click Finish and you will see it appears inside the themes folder rather than inside one of the actual themes.
Now that I have a file, I am going to put in some dummy content, so that we can see that it works. So I will simply go echo, so that it types out whatever I put in there, and I will say "Hello!", end the line, and end my php delimeter. Now if I save this and go back to my browser and reload the front page, you will see that nothing happens. That's simply because although we made the file, we haven't yet called it into the theme. So that's the next step.
I will go back and into my cooking theme folder. Like I said before, all functions inside WordPress live in a functions.php file inside the theme, so what we need to do now is create that file as well. So I will go to New, create a file, and create a file called functions.php that's saved under the cooking folder. So now we have a functions file that we will append next to the functions file from a parent theme. So we don't need to copy the functions from the parent theme over; all we need to do is add new functions inside here.
What we need to do first is to create a function that calls this posttypes.php file. The great thing about php is there's an actual function that does this for us and it's called include. So if simply say include and I only want it once, I will say include_once, and then we give URL to the file we want to include, it will work. Now theoretically, we should be able to just say ../ and then poststype.php to jump back one folder and then open posttype.php, but that's not going to work.
In this case, we need to hard core the actual URL in. But if I hard core the URL to the file in saying, localhost/ WordPress/da-da-da, it won't work, if we move the child theme somewhere else. So what we need to do is use another function to grab the actual live URL dynamically. That function is called ABSPATH. Next to ABSPATH we need to append the actual URL, so I go space, dot, to append it, and then quotation, and I will say wp- content/themes/and then posttypes.php, end the line with a semicolon, and end the PHP delimeter.
Using this, we should now see that word Hello! appear inside our theme. So I will Save it, go back to my browser, Reload, and you will see Hello! appears here at the very top. That means our child theme now grabs the posttypes.php file living outside the child theme and appends it into the functions. Now just for ease-of-use, I've added this code into my code-snippets file, so you can simply go in here and copy that code out, if you can't remember that exact syntax.
Well, just to reiterate, it's include_ once, ABSPATH, which points to the core sites of where the site is. So it will be www.yoursite.com and then we append the rest of the address here. Although not technically necessary, placing custom post type and custom taxonomies functions in a separate abstraction layer or file makes it easier for you to move the functions to a different or even multiple themes without having to copy and paste or to make changes to the existing functions file.
Furthermore, if you run several themes with the same post types, you can change one file and have these changes permeate throughout all the themes. Simply put, you put all the important stuff in one central location and just call it from there, rather than putting all the important stuff in each individual location.
There are currently no FAQs about Create an Online Portfolio with WordPress.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.