Advertisement
sayful

WP Filterable Portfolio

Feb 16th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.75 KB | None | 0 0
  1. <?php
  2. /*=======================================
  3. * call this function to register the custom post type
  4. =======================================*/
  5. add_action( 'init', 'themename_custom_post_type' );
  6. function themename_custom_post_type() {
  7.     register_post_type( 'themename_portfolio',
  8.         array(
  9.             'labels' => array(
  10.                 'name' => __( 'Portfolios' ),
  11.                 'singular_name' => __( 'Portfolio' ),
  12.                 'add_new' => __( 'Add New' ),
  13.                 'add_new_item' => __( 'Add New Portfolio' ),
  14.                 'edit_item' => __( 'Edit Portfolio' ),
  15.                 'new_item' => __( 'New Portfolio' ),
  16.                 'view_item' => __( 'View Portfolio' ),
  17.                 'search_items' => __( 'Search Portfolio' ),
  18.                 'not_found' => __( 'No Portfolio found' ),
  19.                 'not_found_in_trash' => __( 'No Portfolio found in Trash' )
  20.             ),
  21.         'public' => true,
  22.         'has_archive' => true,
  23.         'exclude_from_search' => true,
  24.         'show_ui' => true,
  25.         'show_in_admin_bar' => true,
  26.         'menu_position' => 5,
  27.         'menu_icon' => 'dashicons-images-alt2', // http://melchoyce.github.io/dashicons/
  28.         'capability_type' => 'page',
  29.         'hierarchical' => false,
  30.         'rewrite' => array( 'slug' => 'slide' ),
  31.         'supports' => array( 'title','editor','thumbnail'),
  32.         )
  33.     );
  34. }
  35.  
  36. /*=======================================
  37. * call this function to register the custom taxonomy
  38. =======================================*/
  39. function themename_custom_taxonomy() {
  40.     register_taxonomy(
  41.     'portfolio_cat',
  42.     'themename_portfolio',
  43.     array(
  44.         'hierarchical'          => true,
  45.         'label'                         => 'Portfolio Categories',
  46.         'query_var'             => true,
  47.         'rewrite'                       => array(
  48.             'slug'                  => 'portfolio-category',
  49.             )
  50.         )
  51.     );
  52. }
  53. add_action( 'init', 'themename_custom_taxonomy' );
  54.  
  55. /*=======================================================
  56. *To enable  Featured Image (Post Thumbnails) support for Custom post
  57. =======================================================*/
  58. add_theme_support( 'post-thumbnails', array( 'themename_portfolio' ) );
  59. add_image_size( 'portfolio-thumb', 370, 240 );
  60. add_image_size( 'portfolio-large', 740, 480 );
  61. ?>
  62.  
  63. <!--
  64. /*======================================================
  65. *Creating the Portfolio Filter
  66. *Displaying the Portfolio Items
  67. =======================================================*/
  68. -->
  69.  
  70. <div class="portfolio_filter">
  71. <?php
  72.         $terms = get_terms("portfolio_cat");    //To get custom taxonomy catagory name
  73.         $count = count($terms);
  74.         echo '<ul>';
  75.         echo '<li class="filter" data-filter="all">All</li>';
  76.             if ( $count > 0 )
  77.             {  
  78.                 foreach ( $terms as $term ) {
  79.                     $termname = strtolower($term->name);
  80.                     $termname = str_replace(' ', '-', $termname);
  81.                     echo '<li class="filter" data-filter="'.$termname.'">'.$term->name.'</li>';
  82.                 }
  83.             }
  84.     echo "</ul>";
  85. ?>
  86. </div>
  87. <div class="portfolio_content">
  88.            <ul id="Grid"  class="gallery">
  89.         <?php
  90.                 $loop = new WP_Query(array('post_type' => 'themename_portfolio', 'posts_per_page' => -1));
  91.                 $count =0;
  92.         ?>
  93.                 <?php if ( $loop ) :
  94.                      
  95.                 while ( $loop->have_posts() ) : $loop->the_post(); ?>
  96.                      
  97.                     <?php
  98.                     $terms = get_the_terms( $post->ID, 'portfolio_cat' );   //To get custom taxonomy catagory name
  99.                                      
  100.                     if ( $terms && ! is_wp_error( $terms ) ) :
  101.                             $links = array();
  102.  
  103.                             foreach ( $terms as $term )
  104.                             {
  105.                                 $links[] = $term->name;
  106.                             }
  107.                             $links = str_replace(' ', '-', $links);
  108.                             $tax = join( " ", $links );    
  109.                     else :
  110.                             $tax = '';
  111.                     endif;
  112.                     ?>
  113.                        
  114.                     <li class="mix all <?php echo strtolower($tax); ?>">
  115.                                     <div class="single_portfolio">
  116.                                       <?php the_post_thumbnail('portfolio-thumb'); ?>
  117.                 <div class="mask">
  118.                     <?php $portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-large' ); ?>    
  119.                     <a href="<?php echo $portfolio_large[0]; ?>" rel="prettyPhoto" title="This is the description"><i class=" search_icon fa fa-search"></i></a>
  120.                     <a href="<?php the_permalink();?>"><i class=" picture_icon fa fa-picture-o"></i></a>
  121.                 </div>
  122.             </div>
  123.                        </li>
  124.                          
  125.                 <?php endwhile; else: ?>
  126.                      
  127.                     <li class="error-not-found">Sorry, no portfolio entries found.</li>
  128.                          
  129.                 <?php endif; ?>
  130.             </ul>
  131. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement