Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ***************How to Dynamic Tab with custom post by shortcode query***********
- 1. First register a *custom post* and *custom taxonomy* in functions.php file/custom-post.php file like bellow..
- //custom register for *Testimonial*
- function testimonial_custom_post() {
- register_post_type( 'testimonial_items',
- array(
- 'labels' => array(
- 'name' => __( 'testimonials' ),
- 'singular_name' => __( 'testimonial' ),
- 'all_items' => __( 'All testimonial' ),
- 'add_new_item' => __( 'Add new testimonial' ),
- 'search_items' => __( 'Search testimonial' ),
- 'not_found' => __( 'No testimonial found,Please!!! try with another keyword' ),
- 'not_found_in_trash' => __( 'No testimonial found in trash' ),
- 'parent_item' => __( 'Parent testimonial' ),
- 'parent_item_colon' => __( 'Parent testimonial' ),
- 'edit_item' => __( 'Edit testimonial' ),
- 'update_item' => __( 'Update testimonial' ),
- 'view_item' => __( 'View testimonial' ),
- 'new_item_name' => __( 'New testimonial' ),
- 'menu_name' => __( 'testimonial' )
- ),
- 'public' => true,
- 'menu_icon' => 'dashicons-clipboard',
- 'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
- 'has_archive' => true,
- 'menu_position' => 8,
- 'rewrite' => array('slug' => 'testimonial_item')
- )
- );
- }
- add_action('init', 'testimonial_custom_post');
- //for featered images support
- add_theme_support( 'post-thumbnails' );
- //register custom taxonomy *for Testimonial*
- function Testimonial_custom_post_taxonomy() {
- register_taxonomy(
- 'testimonial_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'testimonial_items', //post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Testimonial Category', //Display name
- 'query_var' => true,
- 'show_admin_column' => true,
- 'rewrite' => array(
- 'slug' => 'Testimonial-category', // This controls the base slug that will display before each term
- 'with_front' => true // Don't display the category base before
- )
- )
- );
- }
- add_action('init', 'Testimonial_custom_post_taxonomy');
- 2. Than query only those html code with shortcode which you want to add into custom post in admen panel like bellow.......
- //testimonial images custom post query
- function testimonial_persion_shortcode($atts){
- extract( shortcode_atts( array(
- 'category' => ''
- ), $atts, 'tthumb' ) );
- $q = new WP_Query(
- array('posts_per_page' => -1, 'post_type' => 'testimonial_items', 'testimonial_cat' => $category)
- );
- $list = '<ul class="tabNavigation list-unstyled bottom-0 clearfix row onepixel">';
- while($q->have_posts()) : $q->the_post();
- $idd = get_the_ID();
- $auther_images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
- $list .= '
- <li class="bottom-1 col-md-3 col-xs-3">
- <a data-toggle="tab" href="#testimonial-'.$idd.'">
- <img class="img-responsive" src="'.$auther_images[0].'" alt="">
- </a>
- </li>
- ';
- endwhile;
- $list.= '</ul>';
- wp_reset_query();
- return $list;
- }
- add_shortcode('tthumb', 'testimonial_persion_shortcode');
- //testimonial content custom post query
- function testimonial_content_shortcode($atts){
- extract( shortcode_atts( array(
- 'category' => ''
- ), $atts, 'tcontent' ) );
- $q = new WP_Query(
- array('posts_per_page' => -1, 'post_type' => 'testimonial_items', 'testimonial_cat' => $category)
- );
- $list = '<div class="col-md-6 wow fadeIn" data-wow-duration="0.6s" data-wow-delay="0.3s">';
- while($q->have_posts()) : $q->the_post();
- $idd = get_the_ID();
- $auther_images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
- $athor_position = get_post_meta($idd, 'athor_position', true);
- $list .= '
- <div id="testimonial-'.$idd.'" class="testimonail-detail">
- <p>'.get_the_content().'</p>
- <div class="testimonial-info">
- <span class="name">
- '.get_the_title().'
- </span>
- <span class="company">
- '.$athor_position.'
- </span>
- </div>
- </div>
- ';
- endwhile;
- $list.= '</div>';
- wp_reset_query();
- return $list;
- }
- add_shortcode('tcontent', 'testimonial_content_shortcode');
- 3. Now call this shortcode in index.php to add it like bellow....
- <?php echo do_shortcode('[portfolio title="Recent Projects" dsc="the latest work of our team" more="#" build="#"]');?>
- <?php echo do_shortcode('[form_blog title="From the blog" dsc="sometime we want to share something" category="shome"]'); ?>
- 4. Than Combination your those shortcode to make it in one shortcode......
- //Double shortcode combination to make it one
- function testimonial_final_shortcode($atts, $content = null) {
- //add attribute
- extract( shortcode_atts( array(
- 'title' => '',
- 'dsc' => '',
- 'category' => ''
- ), $atts, 'testimonial'));
- return'<div id="testimonials" class="section cover top-40" data-padding="40px 0" data-bg="
- <?php echo get_template_directory_uri(); ?>
- /images/demo/section-2.jpg" data-bgmark="rgba(145, 145, 145, 0.4)">
- <div class="container white">
- <div class="heading-area white text-left bottom-30 wow fadeInDown" data-wow-duration="0.6s" data-wow-delay="0.3s">
- <h4 class="heading white large">
- '.$title.'
- </h4>
- <span class="sub-heading">
- '.$dsc.'
- </span>
- </div>
- <div class="row">
- <div class="col-md-6 bottom-sm-30 bottom-xs-30 wow fadeIn" data-wow-duration="0.6s" data-wow-delay="0.6s">
- <div class="tabs testimonial">
- '.do_shortcode('[tthumb category="'.$category.'"]').'
- </div>
- </div>
- '.do_shortcode('[tcontent category="'.$category.'"]').'
- </div>
- </div>
- </div>';
- }
- add_shortcode('testimonial', 'testimonial_final_shortcode');
- বি:দ্র: যদি shortcode এর অংশ টুকু আলাদা file -এ করতে হয় তাহলে inc নামে একটি folder করে shorcode.php file এর মধ্যে করতে হবে এবং shorcode.php file টিকে functions.php file -এ call করতে হবে এভাবে.......
- include_once('inc/shortcode.php');
- Note: আলাদা file-এ করাই সবচেয়ে ভালো ।
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement