This is the second in a series of lessons about how to use Wordpress as a full-featured Content Management System. The first post, Wordpress 101, of this two-part lesson is located here. Wordpress 102 will continue on where that one left off and we will address:
- How to utilize unique pages, with a unique layout
- How to include “pages” in other areas of your template
- How to make a portfolio with thumbnails and full size images
- Customizing the Templates
In the last tutorial, we discussed how to set your home page as a unique page – and how to rename and link to your blog. Chances are good that if you are going to run an entire site through Wordpress, there will be more to it than just home and blog. What we need to look at now is how to create a “Page” and how to link to it in our navigation.
You’re going to need your favorite text editor again, we’re going to create a new template. Open page.php which should be located in (/wp-content/themes/YourTheme) add the following code at the top.
/*
Template Name: About
*/
?>
Save this page as about.php and upload it to your server.
Next, log into your Wordpress admin section and click on “write” then “write page”. Give it a title (let’s call this one “about us” and fill in some content). In the side bar you will see “Page Templates” click on this and select “About”. Now your “about us” page is using this new template – you can modify this template to your liking.
Now not to get too deep into template modification, but what if you wanted to put a little bit about yourself in the side bar of your about us page? Now you could certainly open about.php (that we just created) and insert your html code, save, and upload. That would work, but it kind of defeats the purpose of a CMS, which is to have all of your site’s content update able via the CMS and not by editing files.
A nifty little plugin called Improved Include Page will take care of this for us. First download the plugin and install it – there is great information on how to install this plugin (and how to use it for that matter) on the download page. So we won’t go into the specifics here.
Got it installed? Good, let’s keep going…
Yet again we are going to start with making a new page in the admin. Create a page, make the headline your name and in the body just type your contact information. Save your changes. For our purposes, we will need edit sidebar.php (the Wordpress Codex has great information on modifying sidebar.php), again this can be found in your theme (/wp-content/themes/YourTheme) directory. Now go to “Manage” and click on “Pages” – the first column has each page’s unique id. Copy (or write down if your old school) the ID of the page you just created (it will be in the column labeled ID). Also make note of the ID of your about us page. Got those two numbers? Good, let’s open sidebar.php in the text editor. At the bottom of the file just inside the tag place the following code.
if(is_page('8')) if(function_exists('iinclude_page')) iinclude_page(12,'displayTitle=true&titleBefore=
‘);
?>Where I have the number 12 you need the ID of your new page (page snippet) that has your contact information. Where I have the number 8 you will need the ID of your about us page (parent page).
What is this code saying? OK, let’s take a look.
if(is_page('8'))
says if this page has the ID of “8″ then do the stuff that’s to the right (more on these conditional statements within Wordpress can be found on the Codex).
This code
if(function_exists('iinclude_page')) iinclude_page(12,'displayTitle=true&titleBefore=
‘);
Says if we have the function “iinclude_page” (which we do, cause we installed the plugin) include page ID 12The rest of the stuff is formatting – and if you care to delve into that, it’s all explained on the plugin download page. If you browse your site now, you should have your contact information included in the sidebar of only your about page. Cool huh?
These two pieces of information should allow you to accomplish 99% of the things you’ll want to do with your site. If you’re anything like me, though, you’re scratching your head wondering about that other 1%. So let’s look at one of those “other” things that a site might need. For my purposes, I also needed a portfolio (so that’s what we’ll address here).
I looked and looked for an “easy” way (that is to say plugin, widget etc) of doing this, but every time I started heading down a path, I would dead end into something that didn’t sit well with me. When things like that happen, it’s time to open the text editor and do it on our own. My idea was to have small images displayed in the sidebar that would link to a page containing a larger image and a description of the project. Since it wouldn’t be appropriate on all pages, I only wanted this to happen in the “portfolio” section. Now admittedly the rest of this is kind of a hack as it will require using a mix of FTP/code editor/wp-admin to update this section, but it works and sometimes that is the most important thing. Now someone who wanted to spend time with this could definitely turn this into a Plugin or a Widget – and if that someone is you, please let me know. With that being said, let’s hack!
First, let’s create a new page template for everything in our “Portfolio” section. Crack open your text editor and open your about.php file (provided you have done this tutorial from the start, you should have this file, if not – just read above and create a portfolio.php file). In the top of the file where it says:
/*
Template Name: About
*/
?>
Change to
/*
Template Name: Portfolio
*/
?>
Save this file as portfolio.php, upload (/wp-content/templates/your template name/portfolio.php) and voilla, a new template is born. Now let’s go to the admin section and create a page using this template. Eventually, you’ll probably want images and all kinds of cool things in your portfolio, but for now, just create a page, type some content in it – assign it’s page parent as “Portfolio” (after all, portfolio pages should be in the portfolio section) and lastly, but VERY IMPORTANT make the page slug the name of this page/client ie “clientname” (no spaces – no caps – that’s the important part) – more on that in a bit. Save this file and publish it.
We’re going to create a new sidebar include file that will only be used on our portfolio.php template. This will allow all pages with in our “Portfolio” section to use the same sidebar – which will be a different sidebar from the sidebar used for the rest of our pages. Open up your sidebar.php file (located in /wp-content/themes/your theme name/sidebar.php) and replace the code that is in it with the following (basically this code reads through everything in a directory – outputs all of the files contained within it to an array then echoes out that array):
Save this file as portfolioSidebar.php and upload it to your themes directory (you know the link by now, right?). In order for this to work, we need to tell our Portfolio template to use this sidebar and not the “normal” one. So open portfolio.php in your editor again.
look for this code:
and replace it with this (thanks again to the Wordpress Codes for this little bit of knowledge):
Save portfolio.php and upload it – now your Portfolio section has a unique side bar. Don’t look at it yet though, cause we’re not done. If you stop here, you will get an error message.
Our files should be good now, and we’ve created some content for the page – let’s get to making the image show up and having it link to that page. Open your FTP application, create a new directory in /wp-content/templates/your template name/
called “portfolio” this is where you are going to upload the thumbnail images that you want displayed in your side bar. Now make a thumbnail image and upload it (you’re on your own here) – name it as you slugged the page above (this is IMPORTANT – the slug and file name MUST match) ie clientname.jpg. That is it – if you view your site now and go to your portfolio section, you should see images in your new side bar and those images should link to their pages.
I think that wraps it up for Wordpress 102. Please let us know if you have ideas for a Wordpress 103 and happy blogging!


