Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*=======================================
- * call this function to register the custom post type
- =======================================*/
- add_action( 'init', 'themename_custom_post_type' );
- function themename_custom_post_type() {
- register_post_type( 'themename_portfolio',
- array(
- 'labels' => array(
- 'name' => __( 'Portfolios' ),
- 'singular_name' => __( 'Portfolio' ),
- 'add_new' => __( 'Add New' ),
- 'add_new_item' => __( 'Add New Portfolio' ),
- 'edit_item' => __( 'Edit Portfolio' ),
- 'new_item' => __( 'New Portfolio' ),
- 'view_item' => __( 'View Portfolio' ),
- 'search_items' => __( 'Search Portfolio' ),
- 'not_found' => __( 'No Portfolio found' ),
- 'not_found_in_trash' => __( 'No Portfolio found in Trash' )
- ),
- 'public' => true,
- 'has_archive' => true,
- 'exclude_from_search' => true,
- 'show_ui' => true,
- 'show_in_admin_bar' => true,
- 'menu_position' => 5,
- 'menu_icon' => 'dashicons-images-alt2', // http://melchoyce.github.io/dashicons/
- 'capability_type' => 'page',
- 'hierarchical' => false,
- 'rewrite' => array( 'slug' => 'slide' ),
- 'supports' => array( 'title','editor','thumbnail'),
- )
- );
- }
- /*=======================================
- * call this function to register the custom taxonomy
- =======================================*/
- function themename_custom_taxonomy() {
- register_taxonomy(
- 'portfolio_cat',
- 'themename_portfolio',
- array(
- 'hierarchical' => true,
- 'label' => 'Portfolio Categories',
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'portfolio-category',
- )
- )
- );
- }
- add_action( 'init', 'themename_custom_taxonomy' );
- /*=======================================================
- *To enable Featured Image (Post Thumbnails) support for Custom post
- =======================================================*/
- add_theme_support( 'post-thumbnails', array( 'themename_portfolio' ) );
- add_image_size( 'portfolio-thumb', 370, 240 );
- add_image_size( 'portfolio-large', 740, 480 );
- ?>
- <!--
- /*======================================================
- *Creating the Portfolio Filter
- *Displaying the Portfolio Items
- =======================================================*/
- -->
- <div class="portfolio_filter">
- <?php
- $terms = get_terms("portfolio_cat"); //To get custom taxonomy catagory name
- $count = count($terms);
- echo '<ul>';
- echo '<li class="filter" data-filter="all">All</li>';
- if ( $count > 0 )
- {
- foreach ( $terms as $term ) {
- $termname = strtolower($term->name);
- $termname = str_replace(' ', '-', $termname);
- echo '<li class="filter" data-filter="'.$termname.'">'.$term->name.'</li>';
- }
- }
- echo "</ul>";
- ?>
- </div>
- <div class="portfolio_content">
- <ul id="Grid" class="gallery">
- <?php
- $loop = new WP_Query(array('post_type' => 'themename_portfolio', 'posts_per_page' => -1));
- $count =0;
- ?>
- <?php if ( $loop ) :
- while ( $loop->have_posts() ) : $loop->the_post(); ?>
- <?php
- $terms = get_the_terms( $post->ID, 'portfolio_cat' ); //To get custom taxonomy catagory name
- if ( $terms && ! is_wp_error( $terms ) ) :
- $links = array();
- foreach ( $terms as $term )
- {
- $links[] = $term->name;
- }
- $links = str_replace(' ', '-', $links);
- $tax = join( " ", $links );
- else :
- $tax = '';
- endif;
- ?>
- <li class="mix all <?php echo strtolower($tax); ?>">
- <div class="single_portfolio">
- <?php the_post_thumbnail('portfolio-thumb'); ?>
- <div class="mask">
- <?php $portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-large' ); ?>
- <a href="<?php echo $portfolio_large[0]; ?>" rel="prettyPhoto" title="This is the description"><i class=" search_icon fa fa-search"></i></a>
- <a href="<?php the_permalink();?>"><i class=" picture_icon fa fa-picture-o"></i></a>
- </div>
- </div>
- </li>
- <?php endwhile; else: ?>
- <li class="error-not-found">Sorry, no portfolio entries found.</li>
- <?php endif; ?>
- </ul>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement