Advertisement
firoze

Bootstrap Accordion Bar Full Usages By Shortcode

Jul 14th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. <?php
  2. /* ----------------------------------------------------- */
  3. /* Register Custom Post */
  4. /* ----------------------------------------------------- */
  5. function create_post_type() {
  6. /*****************************Bootstrap Accordion bar**************************************************/
  7. register_post_type( 'accordion_bar',
  8. array(
  9. 'labels' => array(
  10. 'name' => __( 'Accordion bars' ),
  11. 'singular_name' => __( 'accordion' ),
  12. 'add_new'=>_('Add New Accordion')
  13. ),
  14. 'public' => true,
  15. 'menu_icon'=> 'dashicons-lock', /* For Dashicons Menu */
  16. 'has_archive' => true,
  17. 'rewrite'=> array( 'slug' => 'accordion' ),
  18. 'supports'=> array( 'title', 'editor', 'custom-fields', '' )
  19.  
  20. )
  21. );
  22.  
  23. }
  24. add_action( 'init', 'create_post_type' );
  25.  
  26.  
  27. // support taxonomy category
  28.  
  29. function taxonomy_firoze(){
  30.  
  31. /*******Bootstrap Accordion bar start***********/
  32. register_taxonomy(
  33. 'accordion_category', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  34. 'accordion_bar', //post type name
  35. array(
  36. 'hierarchical' => true,
  37. 'label' => 'Accordion Category', //Display name
  38. 'query_var' => true,
  39. 'rewrite' => array(
  40. 'slug' => 'page-category', // This controls the base slug that will display before each term
  41. 'with_front' => false // Don't display the category base before
  42. )
  43. )
  44. );
  45. /*******Bootstrap Accordion bar end***********/
  46. // create a new taxonomy
  47.  
  48. }
  49. add_action('init' , 'taxonomy_firoze');
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. /*****************************Bootstrap Accordion bar**************************************************/
  58. function items_shortcode($atts){
  59. extract( shortcode_atts( array(
  60. 'category' => '',
  61. 'title' => '',
  62. 'count' => '10'
  63. ), $atts, 'items_do_shortcode' ) ); // this is for do_shortcode where we have to query(to show post)
  64.  
  65. $q = new WP_Query(
  66. array('posts_per_page' => 10,
  67. 'post_type' => 'accordion_bar',
  68. 'accordion_category' => $category, // This price_category From Taxonomy
  69. 'meta_key'=>'accordion_order', //this is for price order Need to show in CMB in id
  70. 'orderby'=>'meta_value_number', //this is for price order number
  71. 'order'=>'ASC' //this is for price order
  72.  
  73. )
  74. );
  75.  
  76.  
  77. $list = ''; // wrapper will go here
  78. while($q->have_posts()) : $q->the_post();
  79. $idd = get_the_ID();
  80. $heading_number = get_post_meta( $idd, 'heading_number', true ); // This have to show on (CMB) for id
  81. $aria_expanded = get_post_meta( $idd, 'aria_expanded', true ); // This have to show on (CMB) for id
  82. $in_expanded = get_post_meta( $idd, 'in_expanded', true ); // This have to show on (CMB) for id
  83. $list .= '
  84. <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="'.$aria_expanded.'">
  85. <div class="panel panel-default">
  86. <div class="panel-heading" role="tab" id="heading'.$heading_number.'" style="margin-bottom:px;">
  87. <h4 class="panel-title">
  88. <a data-toggle="collapse" data-parent="#accordion" href="#collapse'.$heading_number.'" aria-expanded="'.$aria_expanded.'" aria-controls="collapse'.$heading_number.'">
  89. '.get_the_title().'
  90. </a>
  91. </h4>
  92. </div>
  93. <div id="collapse'.$heading_number.'" class="panel-collapse collapse '.$in_expanded.'" role="tabpanel" aria-labelledby="heading'.$heading_number.'">
  94. <div class="panel-body" style="color:#000;">
  95. '.get_the_content().'
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. ';
  101. endwhile;
  102. $list.= '';
  103. wp_reset_query();
  104. return $list;
  105. }
  106. add_shortcode('items', 'items_shortcode'); // this is for shortcode & do_shortcode where we have to query(to show post)
  107.  
  108.  
  109. // The below code is for Bootstrap Accordion bar
  110. /************************/
  111.  
  112. // [items] // here accordion is category name by that under category i want to show my post
  113. /************************/
  114.  
  115.  
  116.  
  117.  
  118.  
  119. // custom meta box usages for bootstrap accordion bar
  120.  
  121. /*****************************Bootstrap Accordion bar**************************************************/
  122. $meta_boxes['bootstrap_accordion'] = array(
  123. 'id' => 'bootstrap_accordion',
  124. 'title' => __( 'Bootstrap Accordion' ),
  125. 'pages' => array( 'accordion_bar', ), // Post type carry from (custome-posts.php)
  126. 'context' => 'normal',
  127. 'priority' => 'high',
  128. 'show_names' => true, // Show field names on the left
  129. // 'cmb_styles' => true, // Enqueue the CMB stylesheet on the frontend
  130. 'fields' => array(
  131. array(
  132. 'name' => 'Bootstrap Accordion',
  133. 'description' => 'Write your Number like (One, Two) Capital letter',
  134. 'id' => 'heading_number',
  135. 'type' => 'text',
  136. ),
  137.  
  138. array(
  139. 'name' => 'Serial Order',
  140. 'description' => 'Show Your Serials',
  141. 'id' => 'accordion_order',
  142. 'type' => 'text',
  143. ),
  144.  
  145. array(
  146. 'name' => 'Aria Expanded',
  147. 'description' => 'If First Post Then select (true) otherise (false)',
  148. 'id' => 'aria_expanded',
  149. 'type' => 'select',
  150. 'options' => array(
  151. 'true' => __( 'true' ),
  152. 'false' => __( 'false' )
  153.  
  154. ),
  155. ),
  156. array(
  157. 'name' => 'In Expanded',
  158. 'description' => 'Select (in) That You Want To Active(May Be For First Post) otherwise (none)',
  159. 'id' => 'in_expanded',
  160. 'type' => 'select',
  161.  
  162. 'options' => array(
  163. 'In' => __( 'in' ),
  164. 'None' => __( 'none' )
  165.  
  166. ),
  167. ),
  168. ),
  169. );
  170.  
  171.  
  172.  
  173. **********************************************************************************************************************
  174.  
  175. // usages with category supported if want to support category by shortcode then create new category for every post suppose if you want to use 4 post then make seperately 4 new category
  176.  
  177. <div class="container">
  178. <div class="row">
  179. <div class="col-md-6">
  180. <div class="bootstrap_accordion">
  181. <?php
  182. $loop = new WP_Query(array('post_type' => 'accordion_bar', 'posts_per_page' =>-1));
  183. $count =0;
  184. ?>
  185. <?php if ( $loop ) :
  186.  
  187. while ( $loop->have_posts() ) : $loop->the_post(); ?>
  188.  
  189. <?php
  190. $terms = get_the_terms( $post->ID, 'accordion_category' ); // name of the taxonomy
  191.  
  192. if ( $terms && ! is_wp_error( $terms ) ) :
  193. $links = array();
  194.  
  195. foreach ( $terms as $term )
  196. {
  197. $links[] = $term->name;
  198. }
  199. $links = str_replace(' ', '-', $links);
  200. $tax = join( " ", $links );
  201. else :
  202. $tax = '';
  203. endif;
  204. ?>
  205. <?php echo do_shortcode('[items category="'.strtolower($tax).'"]');?>
  206. <?php endwhile;?>
  207. <?php endif; ?>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement