Advertisement
azad_rpi

another-mix-it-up

May 20th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. function styler_theme_features()  {
  2.     // Add theme support for Featured Images
  3.     add_theme_support( 'post-thumbnails', array( 'portfolio' ) ); //post, page, and other custom post type can be added, up to you
  4.     add_image_size( 'portfolio-thumb', 300, 300, true );
  5. }
  6.  
  7. // Hook into the 'after_setup_theme' action
  8. add_action( 'after_setup_theme', 'styler_theme_features' );
  9.  
  10.  
  11. //add "type" taxonomy slug to post class
  12. function styler_portfolio_class( $classes ) {
  13.     global $post;
  14.     $terms = get_the_terms( $post->ID, 'type' );
  15.     if( 'portfolio' === $post->post_type ) {
  16.         unset($classes);
  17.         $classes[] = 'mix';
  18.         foreach ( $terms as $term ) {
  19.             $classes[] = $term->slug;
  20.         }
  21.         return $classes;
  22.     }
  23.     return $classes;
  24. }
  25.  
  26. // Custom query to fetch portfolio items
  27. <div class="portfolio-wrap">
  28.     <ul class="portfolio-filter">
  29.         <?php $terms = get_terms('type', 'hide_empty=0');
  30.             echo '<li class="filter" data-filter="all">All</li>';
  31.             foreach( $terms as $term ) {
  32.                 echo '<li class="filter" data-filter=".' . $term->slug . '">' . $term->name . '</li>';
  33.             }
  34.         ?>
  35.     </ul><!-- /.portfolio-filter -->
  36.     <ul id="portfolio">
  37.         <?php
  38.             query_posts('post_type=portfolio&post_per_page=-1');
  39.             if( have_posts() ):
  40.                 while( have_posts() ): the_post();
  41.         ?>
  42.                 <li <?php post_class(); ?>>
  43.                     <figure>
  44.                         <?php if( has_post_thumbnail() ): ?>
  45.                             <?php the_post_thumbnail( 'portfolio-thumb' ) ?>
  46.                         <?php endif; ?>
  47.                         <figcaption>
  48.                             <h2>
  49.                                 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  50.                             </h2>
  51.                         </figcaption>
  52.                     </figure>
  53.                 </li>
  54.         <?php
  55.                 endwhile;
  56.             endif;
  57.             wp_reset_query();
  58.         ?>
  59.     </ul><!-- /#portfolio -->
  60. </div><!-- /.portfolio-wrap -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement