Here's how to show x latest portfolio entries on any page
-
If you’d like to show, say, the 4 latest portfolio entries on any of your WordPress pages, follow these simple instructions.
1. Open the OTW portfolio template ‘otw-portfolio-paginated.php’. I copied all OTW’s templates to my theme so any plugin updates won’t break my edits.
2. Copy the whole code from lines 10 to lines 76. Also make sure you copy the “otw_pfl_scripts_styles(); /* include the necessary srctips and styles */” and insert it below get_header(); in the theme file(s) you want to show the portfolio entries.
3. Paste the whole big code you copied from OTW to the theme page where you want the latest entries to appear. For me, that was in ‘home-page.php’.
4. Now find this code in your custom theme file where you placed the latest X entries code:
<?php if (is_page()) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('post_type=otw-portfolio&paged='.$paged); } ?>
You simply want to add ‘&posts_per_page=4’ to the query_posts string. Change 4 to the # of latest entries you want to add. So your code will now look like this:
<?php if (is_page()) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('post_type=otw-portfolio&posts_per_page=4&paged='.$paged); } ?>
5. If you want to remove the pagination and filtering for the latest entries, simply find and delete these two pieces of code from your custom theme file:
<?php $taxo = get_object_taxonomies( 'otw-portfolio' ); foreach ( $taxo as $tax_name ) { $categories = get_categories('taxonomy='.$tax_name); $i = 0; $len = count( $categories ); foreach ($categories as $category) { if ($i == 0) { ?><ul class="otw-portfolio-filter"><?php } if ($i > 0) { $sep = '<span class="separator">/</span>'; } echo '<li class="'.$category->category_nicename.'"><a href="'.get_term_link($category->slug, 'otw-portfolio-category').'">'.$sep.$category->cat_name.'</a></li>'; if ($i == $len - 1) { echo '</ul>'; } $i++; } } ?>
<?php otw_pagination_pfl(); ?>
Should work!
- The topic ‘Here's how to show x latest portfolio entries on any page’ is closed to new replies.