Advertisement
arnabkumar

shortcode_mixitup

May 8th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.49 KB | None | 0 0
  1. <?php
  2.  
  3. // Mixitup custom post
  4.  
  5.    
  6.  
  7.     //Step-1: Register custom post for mixitup.  Copy this code in fuctions.php or custom-posts.php
  8.      
  9.     function portfolio_custom_post() {
  10.      
  11.             register_post_type( 'mixitup',
  12.                     array(
  13.                             'labels' => array(
  14.                                     'name' => __( 'MixITUp Items' ),
  15.                                     'singular_name' => __( 'Mixitup Item' )
  16.                             ),
  17.                             'public' => true,
  18.                             'supports' => array('title', 'editor', 'custom-fields','thumbnail'),
  19.                             'has_archive' => true,
  20.                             'menu_position' => 5,
  21.                             'rewrite' => array('slug' => 'mixitup'),
  22.                     )
  23.             );
  24.     }
  25.     add_action( 'init', 'portfolio_custom_post' );
  26.      
  27.     //Step-2: Register custom taxonomy for mixitup category. Copy this code in fuctions.php or custom-posts.php
  28.  
  29.  
  30. // custom taxonmy
  31.  
  32.  
  33.  
  34.  
  35.  function mixitup_taxonomy() {
  36.             register_taxonomy(
  37.                     'mixitup_category',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  38.                     'mixitup',                  //post type name
  39.                     array(
  40.                             'hierarchical'          => true,
  41.                             'label'                         => 'mixitup Category',  //Display name
  42.                             'query_var'             => true,
  43.                             'show_admin_column'             => true,
  44.                             'rewrite'                       => array(
  45.                                     'slug'                  => 'mixitup-category', // This controls the base slug that will display before each term
  46.                                     'with_front'    => true // Don't display the category base before
  47.                                     )
  48.                             )
  49.             );
  50.      
  51.     }
  52.     add_action( 'init', 'mixitup_taxonomy');
  53.    
  54.    
  55.     // shortcode with post query
  56.  
  57.    
  58.    
  59.    
  60.     function p_shortcode($atts){
  61.             extract( shortcode_atts( array(
  62.                     'category' => ''
  63.             ), $atts, 'anyname' ) );
  64.            
  65.         $q = new WP_Query(
  66.             array('posts_per_page' => '-1', 'post_type' => 'mixitup')
  67.             );            
  68.             //Given -1 for showing unlimited post and post name must be same as custom post and taxonomy post name(mixitup) .
  69.      
  70.     //Portfolio taxanomy query
  71.             $args = array(
  72.                     'post_type' => 'mixitup',
  73.                     'paged' => $paged,
  74.                     'posts_per_page' => $data['portfolio_items'],
  75.             );
  76.      
  77.             $portfolio = new WP_Query($args);
  78.             if(is_array($portfolio->posts) && !empty($portfolio->posts)) {
  79.                     foreach($portfolio->posts as $gallery_post) {
  80.                             $post_taxs = wp_get_post_terms($gallery_post->ID, 'mixitup_category', array("fields" => "all"));
  81.                             if(is_array($post_taxs) && !empty($post_taxs)) {
  82.                                     foreach($post_taxs as $post_tax) {
  83.                                             $portfolio_taxs[$post_tax->slug] = $post_tax->name;
  84.                                     }
  85.                             }
  86.                     }
  87.             } //Here must be used category name (mixitup_category).
  88.             if(is_array($portfolio_taxs) && !empty($portfolio_taxs) && get_post_meta($post->ID, 'pyre_portfolio_filters', true) != 'no'):
  89.     ?>
  90.                     <!-- Here is HTML nav menu and Query -->
  91.                    
  92.                     <nav class="project-filter nav horizontal">
  93.                             <ul>
  94.     <li class="active"><a href="#" data-filter="*">All</a></li>
  95.     <?php foreach($portfolio_taxs as $portfolio_tax_slug => $portfolio_tax_name): ?>
  96.     <li><a href="#" data-filter=".<?php echo $portfolio_tax_slug; ?>"><?php echo $portfolio_tax_name; ?></a></li>
  97.     <?php endforeach; ?>
  98.                             </ul>
  99.                     </nav>
  100.      
  101.                     <?php endif; ?>
  102.      
  103.     <?php
  104.      
  105.             $list = '              
  106.                            <div class="projects row">';
  107.             while($q->have_posts()) : $q->the_post();
  108.                     $idd = get_the_ID();
  109.                     $portfolio_subtitle = get_post_meta($idd, 'portfolio_subtitle', true);
  110.                     $filterr = get_post_meta($idd, 'filterr', true);
  111.                     $small_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'mxt_small_image' );
  112.                     $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'mxt_large_image' );
  113.                    
  114.                     //Get Texanmy class
  115.                    
  116.                     $item_classes = '';
  117.                     $item_cats = get_the_terms($post->ID, 'mixitup_category');
  118.                     if($item_cats):
  119.                     foreach($item_cats as $item_cat) {
  120.                             $item_classes .= $item_cat->slug . ' ';
  121.                     }
  122.                     endif;
  123.                            
  124.            
  125.                     $list .= '
  126.                            //Here is HTML portfolio start and dynamic query  
  127.                            
  128.                            <!-- project 1 -->
  129.                            <div class="col-27 '.$item_classes.'">
  130.                                    <article class="project">
  131.                                            <figure class="project-thumb">
  132.                                                    <img src="'.$small_image_url[0].'" alt="" />
  133.                                                    <figcaption class="middle">
  134.                                                            <div>
  135.                                                                    <a href="'.$full_image_url[0].'" class="icon circle medium lightbox"  title="'.get_the_title().'"><i class="fa fa-search"></i></a>
  136.                                                                    <a href="'.get_permalink().'" class="icon circle medium"><i class="fa fa-link"></i></a>
  137.                                                            </div>
  138.                                                    </figcaption>
  139.                                            </figure>
  140.    
  141.                                            <header class="project-header">
  142.                                                    <h4 class="project-title"><a href="'.get_permalink().'">'.get_the_title().'</a></h4>
  143.                                                    <div class="project-meta">'.$portfolio_subtitle.'</div>
  144.                                            </header>
  145.                                    </article>
  146.                            </div>
  147.                            //Here is HTML portfolio query end
  148.                    ';        
  149.             endwhile;
  150.             $list.= '</div>';
  151.             wp_reset_query();
  152.             return $list;
  153.     }
  154.     add_shortcode('mixituptab', 'p_shortcode');
  155.      
  156.    
  157.     /*Used [mixituptab] shortcode in page or <?php echo do_shortcode('[mixiuptab]');?>
  158.     /it in your fix position. */
  159.  
  160.    // then create a category and post to this category , you can give any name of category
  161.  
  162. /* note use image crop
  163.   add_image_size( 'portfolio_thumb_img_lightbox', 775, 336, true );
  164.  
  165.   set_post_thumbnail_size( 200, 200, true );
  166.   add_image_size( 'mixitup', 270, 180, true );
  167.   */
  168.  
  169. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement