If you’ve clicked through my site a bit, you’ve probably stumbled across my nifty portfolio page. Since the mechanics of the page are largely based on CSS and PHP, you can’t get much insight into my method through a page source view. I thought I’d be nice and spill the beans.
I set up the basic Wordpress site first, the portfolio was one of the last features I added. To get started, I created a subdirectory named “portfolio” in the base folder of the wordpress install. I populated that folder with subdirectories containing my site designs.
I like to keep a full copy of the designs I create. That way I have something to display in my portfolio if the business closes or the client fails to maintain their hosting or domain services. If the site is live I just rename index.php to indexa.php, and create a new index file that redirects to the live url. Anyone clicking a link to that site’s subdirectory will go straight to the live site, but a copy of all the files still live on my server.
So, at this point we have a directory tree structure that looks something like this:
Base Install Folder
Portfolio
Site One
Site Two
Site Three
Then I created a Wordpress page template titled “Portfolio”. It uses PHP to read the contents of the portfolio subdirectory and echo them within individual divs, setting different classes for the even and odd rows. I insert a file called “info” in each subdirectory which contains a basic description of the site. The PHP script reads that information into our portfolio display. Here is the code of my portfolio page template:
<?php
/*
Template Name: Portfolio
*/
?>
<?php get_header(); ?>
<div id="wrappinner">
<div id="main">
<div id="portfolio">
<?php
//set portfolio directory path
$path= "/home/bonnie/public_html/portfolio/";
//set base url
$url= "http://www.bonnieshull.com/portfolio/"
//Open portfolio directory
$dir = opendir("portfolio");
//List files in portfolio directory
while (($file = readdir($dir)) !== false)
{
//exclude private files and directories
if( $file == '.' || $file == '..' )
continue;
$info= "$path$file/info";
$description = file_get_contents($info);
if( $flag == 'on' )
{
echo "<div class=\"on\">
<a href=\"$url$file\" target=\"_blank\">".$file."</a>
<p> $description </p></div>\n";
$flag=off;
}
else
{
echo "<div class=\"off\">
<a href=\"$url$file\" target=\"_blank\">".$file."</a>
<p> $description </p></div>\n";
$flag=on;
}
}
closedir($dir);
?>
</div><!-- end portfolio -->
</div><!-- end #main -->
</div><!-- end #wrappinner -->
<?php get_footer(); ?>
Next I created a Wordpress Page titled “My Portfolio” Its very important that the Wordpress portfolio page has a slightly different name than the portfolio directory. I set the default page template to “portfolio”, and I’m ready to go. At this point there will be a “Portfolio” tab in my page navigation menu, and the page will display a list of directory names residing within the portfolio subdirectory. Functional, but ugly.
The final touch is CSS styling, appended to the end of my main stylesheet. Here is a sample:
/*
//////////////////////////////////////////////////////
ZEBRA TABlE
//////////////////////////////////////////////////////
*/
#portfolio {
padding-bottom: 20px;
border-top: 1px solid #cccccc;
width:500px;
}
#portfolio p {
color:#666666;
float:right;
width:350px;
margin:10px 10px 0px 0px;
}
#portfolio div {
border-bottom: 1px solid #cccccc;
}
.on {
background:#FBE6E3;
width:500px;
height:50px;
}
.off {
background:#ffffff;
width:500px;
height:50px;
}
.on a, .off a {
float:left;
text-transform:uppercase;
color:#6E5E5E;
margin: 10px 0px 0px 10px;
}
.on a:hover, .off a:hover {
text-decoration:underline;
float:left;
text-transform:uppercase;
color:#C74E45;
margin: 10px 0px 0px 10px;
}
Finally, I insert an index page in the portfolio directory, redirecting visitors to www.bonnieshull.com/my-portfolio. For a bit of added security I password protect any private subdirectories within the portfolio directory.
So, that’s how I did it. I hope this guide helps you out 