I’ve spent some time in the last few days updating the portfolio design for the site. Each item in my portfolio is a seperate WordPress page. I wanted the portfolio index to highlight the most recent portfolio items in a list, and to update this list automatically every time I add a new item.

Highlighting recent posts in WordPress is really easy. The basic WordPress index.php page does it automatically, adding each new blog post to the page as it’s written. It’s also easy to add links to those posts through sidebar widgets. It’s more difficult to highlight pages based on when they were created. Pages are supposed to be more static, so date based calls to that content is less common.
Making WordPress Look On Pages As Posts
The portfolio page on my site uses a custom template. I worked on some code to make WordPress look at new pages in the same way it looks at posts, and display them based on how recently they were created.
<?php $portfolio_items = array(
'post_type' => 'page',
'showposts' => 3
);
$posts = get_posts($portfolio_items);
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
} } ?>
This makes WordPress pull down pages as $portfolio_items (this can be defined as anything), which are defined to render in the same was as posts. I can then define how many I want to show.
Displaying The Information On The Page
Now I need to display the information on the page (the above code makes WordPress pull down the correct information, but doesn’t display anything. I can do this by adding code in the same way as I’d display any post or page when developing a WordPress template.
<?php $portfolio_items = array(
'post_type' => 'page',
'showposts' => 3
);
$posts = get_posts($portfolio_items);
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to
<?php the_title() ; ?> portfolio page"><?php the_title(); ?></a></li>
<?php } } ?>
I just want to display the three most recent pages as links in a list, but you could display excerpts from the page, full articles or any other information if you wanted.
What If The Page Isn’t A Portfolio Piece?
We’re nearly finished, but there’s one small flaw. If all I ever added to my site was portfolio item pages then there’d be no problem. The code is pulling down any new page, though, so if I add a new page that’s not a portfolio piece it will still show up. I need to limit my results to a subset of pages.
Luckily WordPress makes this easy. All my portfolio item pages are children of the main portfolio page. So I simply need to add a parameter that limits the pages that are getting called.
I need to add a new line:
'post-type' => 'page', 'post_parent' => '163', // this is the new line 'showposts' => 3
‘163′ is the page ID of my portfolio page. Obviously you would need to check on the ID of your own pages if you were implementing this on your own site.
I’m happy with the results. The portfolio page calls a simple list of my three most recent portfolio pieces, and will update that list automatically every time I add a new one.

2 Comments
Thank you! I was looking for this exact code and couldn’t find it til I came across your site. It worked perfectly.
Top porn web – teen girl tube
Porn street walkers – nake girlfriend video
Free porn free downbload – portal erotic movie
Harcore lesbain porn – watch girl movies
Japanese anime porn bitorrent
Absolutly free porn vids
Forum great pictures porn
Veronica hart porn queen 1970 s
Girls porn contest – home sex video
Young hot porn vid – watch porn movie
Wet pantes you porn – nude fuck movies
Bali porn gay – teen adult movie
Porn blowjobs free videos
Tube hamster porn – site sex tube
Amateur free cuckhold porn videos
Granny movie porn free
Young porn ukraine – portal erotic video
Free porn video virgin tear – nude girls movies
Ash and misty porn – incest sex movie
Cluster porn – online sex movie
Gay pizza delivery porn – nude female movies
Free video brutal reality sex porn – online porn movies
Senior women in porn – online sex movies
Pussywillow bbw porn
Kristy morgan porn extra – mature sex tube
Free porn plump chicks – teen porn tube
Animal tour porn
Free porn vidoe sites
Free simon rex gay porn movies
Kelley rippa porn movie – mature fuck film
esrwqouf
Free bi porn galleries – nake erotic movie
Porn cheerleader – watch xxx movies
ukxsvmum
Obiectul nu a fost gasit!
Porn orgy shemale tranny
My first porn 01 hd
svqtpipr
One Trackback
[...] Vía: fog of eternity [...]