Advertisement
shakil97bd

How to Dynamic Tab with custom post by shortc

Aug 14th, 2014
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.87 KB | None | 0 0
  1. ***************How to Dynamic Tab with custom post by shortcode query***********
  2.  
  3. 1. First register a *custom post* and *custom taxonomy* in functions.php file/custom-post.php file like bellow..
  4.  
  5.  
  6.  
  7. //custom register for *Testimonial*
  8.  
  9. function testimonial_custom_post() {
  10.     register_post_type( 'testimonial_items',
  11.         array(
  12.             'labels' => array(
  13.                 'name'              => __( 'testimonials' ),
  14.                 'singular_name'     => __( 'testimonial' ),
  15.                 'all_items'         => __( 'All testimonial' ),
  16.                 'add_new_item'      => __( 'Add new testimonial' ),
  17.                 'search_items'      => __( 'Search testimonial' ),
  18.                 'not_found'         => __( 'No testimonial found,Please!!! try with another keyword' ),
  19.                 'not_found_in_trash' => __( 'No testimonial found in trash' ),
  20.                 'parent_item'       => __( 'Parent testimonial' ),
  21.                 'parent_item_colon' => __( 'Parent testimonial' ),
  22.                 'edit_item'         => __( 'Edit testimonial' ),
  23.                 'update_item'       => __( 'Update testimonial' ),
  24.                 'view_item'         => __( 'View testimonial' ),
  25.                 'new_item_name'     => __( 'New testimonial' ),
  26.                 'menu_name'         => __( 'testimonial' )
  27.                
  28.            
  29.             ),
  30.             'public' => true,
  31.             'menu_icon' => 'dashicons-clipboard',
  32.             'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
  33.             'has_archive' => true,
  34.             'menu_position' => 8,
  35.             'rewrite' => array('slug' => 'testimonial_item')
  36.        
  37.        
  38.         )
  39.    
  40.     );
  41.  
  42.  
  43. }
  44. add_action('init', 'testimonial_custom_post');
  45.  
  46.  
  47. //for featered images support
  48.  
  49. add_theme_support( 'post-thumbnails' );
  50.  
  51.  
  52.  
  53.  
  54. //register custom taxonomy *for Testimonial*
  55.  
  56. function Testimonial_custom_post_taxonomy() {
  57.  
  58.     register_taxonomy(
  59.  
  60.         'testimonial_cat',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  61.  
  62.         'testimonial_items',                  //post type name
  63.  
  64.         array(
  65.  
  66.             'hierarchical'          => true,
  67.  
  68.             'label'                         => 'Testimonial Category',  //Display name
  69.  
  70.             'query_var'             => true,
  71.  
  72.             'show_admin_column'             => true,
  73.  
  74.             'rewrite'                       => array(
  75.  
  76.                 'slug'                  => 'Testimonial-category', // This controls the base slug that will display before each term
  77.  
  78.                 'with_front'    => true // Don't display the category base before
  79.  
  80.                 )
  81.  
  82.             )
  83.  
  84.     );
  85.    
  86. }
  87. add_action('init', 'Testimonial_custom_post_taxonomy');
  88.  
  89.  
  90.  
  91.  
  92. 2. Than query only those html code with shortcode which you want to add into custom post in admen panel like bellow.......
  93.  
  94.  
  95. //testimonial images custom post query
  96.  
  97. function testimonial_persion_shortcode($atts){
  98.     extract( shortcode_atts( array(
  99.         'category' => ''
  100.     ), $atts, 'tthumb' ) );
  101.    
  102.     $q = new WP_Query(
  103.         array('posts_per_page' => -1, 'post_type' => 'testimonial_items', 'testimonial_cat' => $category)
  104.         );     
  105.        
  106.        
  107.     $list = '<ul class="tabNavigation list-unstyled bottom-0 clearfix row onepixel">';
  108.     while($q->have_posts()) : $q->the_post();
  109.         $idd = get_the_ID();
  110.        
  111.         $auther_images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
  112.        
  113.         $list .= '
  114.        
  115.         <li class="bottom-1 col-md-3 col-xs-3">
  116.               <a data-toggle="tab" href="#testimonial-'.$idd.'">
  117.                 <img class="img-responsive" src="'.$auther_images[0].'" alt="">
  118.               </a>
  119.             </li>
  120.        
  121.         ';        
  122.     endwhile;
  123.     $list.= '</ul>';
  124.     wp_reset_query();
  125.     return $list;
  126. }
  127. add_shortcode('tthumb', 'testimonial_persion_shortcode');
  128.  
  129.  
  130. //testimonial content custom post query
  131.  
  132. function testimonial_content_shortcode($atts){
  133.     extract( shortcode_atts( array(
  134.         'category' => ''
  135.     ), $atts, 'tcontent' ) );
  136.    
  137.     $q = new WP_Query(
  138.         array('posts_per_page' => -1, 'post_type' => 'testimonial_items', 'testimonial_cat' => $category)
  139.         );     
  140.        
  141.        
  142.     $list = '<div class="col-md-6 wow fadeIn" data-wow-duration="0.6s" data-wow-delay="0.3s">';
  143.     while($q->have_posts()) : $q->the_post();
  144.         $idd = get_the_ID();
  145.        
  146.         $auther_images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
  147.        
  148.         $athor_position = get_post_meta($idd, 'athor_position', true);
  149.        
  150.         $list .= '
  151.        
  152.         <div id="testimonial-'.$idd.'" class="testimonail-detail">
  153.           <p>'.get_the_content().'</p>
  154.           <div class="testimonial-info">
  155.             <span class="name">
  156.               '.get_the_title().'
  157.             </span>
  158.             <span class="company">
  159.               '.$athor_position.'
  160.             </span>
  161.           </div>
  162.         </div>
  163.        
  164.         ';        
  165.     endwhile;
  166.     $list.= '</div>';
  167.     wp_reset_query();
  168.     return $list;
  169. }
  170. add_shortcode('tcontent', 'testimonial_content_shortcode');
  171.  
  172. 3. Now call this shortcode in index.php to add it like bellow....
  173.  
  174. <?php echo do_shortcode('[portfolio title="Recent Projects" dsc="the latest work of our team" more="#" build="#"]');?>
  175.  
  176. <?php echo do_shortcode('[form_blog title="From the blog" dsc="sometime we want to share something" category="shome"]'); ?>
  177.  
  178.  
  179.  
  180. 4. Than Combination your those shortcode to make it in one shortcode......
  181.  
  182.  
  183.  
  184. //Double shortcode combination to make it one
  185.  
  186. function testimonial_final_shortcode($atts, $content = null) {
  187.    
  188.     //add attribute
  189.     extract( shortcode_atts( array(
  190.         'title' => '',
  191.         'dsc' => '',
  192.         'category' => ''
  193.    
  194.     ), $atts, 'testimonial'));
  195.     return'<div id="testimonials" class="section cover top-40" data-padding="40px 0" data-bg="
  196. <?php echo get_template_directory_uri(); ?>
  197. /images/demo/section-2.jpg" data-bgmark="rgba(145, 145, 145, 0.4)">
  198.   <div class="container white">
  199.     <div class="heading-area white text-left bottom-30 wow fadeInDown" data-wow-duration="0.6s" data-wow-delay="0.3s">
  200.       <h4 class="heading white large">
  201.         '.$title.'
  202.       </h4>
  203.       <span class="sub-heading">
  204.         '.$dsc.'
  205.       </span>
  206.     </div>
  207.    
  208.     <div class="row">
  209.       <div class="col-md-6 bottom-sm-30 bottom-xs-30 wow fadeIn" data-wow-duration="0.6s" data-wow-delay="0.6s">
  210.         <div class="tabs testimonial">
  211.          
  212.           '.do_shortcode('[tthumb category="'.$category.'"]').'
  213.          
  214.         </div>
  215.        
  216.       </div>
  217.      
  218.      
  219.       '.do_shortcode('[tcontent category="'.$category.'"]').'
  220.      
  221.     </div>
  222.    
  223.   </div>
  224.  
  225.     </div>';
  226.  
  227. }
  228. add_shortcode('testimonial', 'testimonial_final_shortcode');
  229.  
  230.  
  231. বি:দ্র: যদি shortcode এর অংশ টুকু আলাদা file -এ করতে হয় তাহলে inc নামে একটি folder করে shorcode.php file এর মধ্যে করতে হবে এবং shorcode.php file টিকে functions.php file -এ call করতে হবে এভাবে.......
  232.  
  233. include_once('inc/shortcode.php');
  234.  
  235.  
  236. Note: আলাদা file-এ করাই সবচেয়ে ভালো ।
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement