Single Page Portfolios With WordPress

Single Page Portfolios With WordPress

Posted on 15. Nov, 2011 by in Coding

I recently needed to make an easily editable single page portfolio (this kind of thing) for a friend. As the budget was essentially nil, I headed over to ThemeForest and chose one of the awesomely designed HTML templates there, only spending about $10 and saving a ton of time in the process.

I then went about the usual porting HTML to WordPress, but I need some way of splitting up the various portfolio sections — about, “what I do” etc — into a separate page for each one so my friend could edit the About page and the about section would change, edit the “What I do” page and the what I do section would change and so on.

I had thought this would be a pain to do, but happily, I was wrong.

Using WP_Query (and not query_posts)I was able to output the contents of one page straight after the other. The code looked something like this:

<?php
  1. $query = new WP_Query( 'page_id=1' );
  2.  
  3. $queryObject = new WP_Query($query);
  4. // The Loop…
  5. if ($queryObject->have_posts()) {
  6.  while ($queryObject->have_posts()) {
  7.   $queryObject->the_post();
  8.   the_content();
  9.   // the title and other styling can be done outside the loop
  10.  }
  11. }
  12.  
  13. // Reset Post Data
  14. wp_reset_postdata();
  15.  
  16. ?>
  17.  
  18. <!– Some styling for the next section –>
  19.  
  20. <?php
  21. $query = new WP_Query( 'page_id=2' ); //just change the ID
  22.  
  23. $queryObject = new WP_Query($query);
  24. // The Loop…
  25. if ($queryObject->have_posts()) {
  26.  while ($queryObject->have_posts()) {
  27.   $queryObject->the_post();
  28.   the_content();
  29.  }
  30. }
  31.  
  32. // Reset Post Data
  33. wp_reset_postdata();
  34.  
  35. ?>

And so on and so forth for all the different pages — it was just a case of getting the page id and putting in a query every time I needed the actual content.

This is another case of simplicity winning the day — this could have been horribly complex, but it was literally a case of just changing one little bit.

Follow on Twitter! Subscribe!

WPShout is hosted by the fine folks at WPWebHost.

You can get exactly the same hosting as WPShout has for $7.95/month with WPWebHost's Freedom Plan.

Plus get 30% off the Freedom Plan with the code WPSHOUT.

Visit WPWebHost

Alex's Gravatar

Alex Denning is the founder of WPShout. A WordPress developer from London, Alex is a keen musician and freelance writer and developer.

You can find Alex on Twitter.

2 Responses to “Single Page Portfolios With WordPress”

  1. komiska

    15. Nov, 2011

    AWESOME! thanks for this! i was alsoe sweating it, but now i can follow to use it for my own portfolio
    THANK YOU!

    Reply to this comment
  2. Beau Bridges

    30. Jan, 2012

    Thanks for the helpful tip Alex!

    Reply to this comment

Leave a Reply

Please use your real name when commenting. Wrap code in <code> tags and make sure HTML is encoded. You can use regular HTML like <a href="... etc.

Get yours questions answered quicker

If you're using this post for paid work and have a question of any complexity then please ask at WPQuestions where you'll get a prompt response.