Advertisement
afsarwebdev

wp-bootstrap-tab-dynamic

Aug 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. //Create custom post and custom texonomy for categories; here custom post name gallery and cutom-texonomy name gallery-cat;
  2. <div class="row">
  3. <!-- Nav tabs -->
  4. <ul class="nav nav-tabs" role="tablist">
  5. <?php
  6. $gallery_terms = get_categories( array(
  7. 'taxonomy' => 'gallery-cat',
  8. 'hide_empty' => false,
  9. ) );
  10. $all_gallery_post = array();
  11. $all_gallery_post_by_category = array();
  12. $is_active = true;
  13. foreach ($gallery_terms as $term_object):
  14. $post_object_arr_by_category_id = get_posts(
  15. array(
  16. 'showposts' => 6,
  17. 'post_type' => 'gallery',
  18. 'tax_query' => array(
  19. array(
  20. 'taxonomy' => 'gallery-cat',
  21. 'field' => 'term_id',
  22. 'terms' => $term_object->term_id
  23. )
  24. )
  25. )
  26. );
  27.  
  28. $all_gallery_post = array_merge($all_gallery_post, $post_object_arr_by_category_id);
  29. $all_gallery_post_by_category[$term_object->slug] = $post_object_arr_by_category_id;
  30. ?>
  31. <li role="presentation" class="<?php echo ( $is_active ) ? 'active' : ''; ?>">
  32. <a href="#gallery-<?php echo $term_object->slug; ?>" role="tab" data-toggle="tab"><?php echo $term_object->name; ?></a>
  33. </li>
  34. <?php $is_active = false; endforeach; ?>
  35. </ul>
  36.  
  37. <!-- Tab panes -->
  38. <div class="tab-content">
  39. <?php foreach ($all_gallery_post_by_category as $gallery_slug => $post_object_arr): ?>
  40. <div role="tabpanel" class="tab-pane <?php echo ( ! $is_active ) ? 'active' : ''; ?>" id="gallery-<?php echo $gallery_slug; ?>">
  41. <?php foreach ($post_object_arr as $post_object): ?>
  42. <div class="col-sm-4 col-xs-6 col-xxs-12">
  43. <div class="ic-single-g-item">
  44. <?php echo get_the_post_thumbnail($post_object->ID, 'gallery-img'); ?>
  45. <div class="ic-title-n-cat">
  46. <h3><?php echo $post_object->post_title; ?></h3>
  47. <!-- <span><?php //echo get_post_meta(get_the_ID(), 'gallery_sub_t', true); ?></span> -->
  48. </div>
  49. </div>
  50. </div>
  51. <?php endforeach; ?>
  52. </div>
  53. <?php $is_active = true; endforeach; ?>
  54. </div>
  55. </div>
  56. //Custom post
  57. register_post_type( 'gallery',
  58. array(
  59. 'labels' => array(
  60. 'name' => __( 'Gallery' ),
  61. 'singular_name' => __( 'gallery' ),
  62. 'add_new_item' => __( 'Add new gallery item' )
  63. ),
  64. 'public' => true,
  65. 'rewrite' => array( 'slug' => 'galleries' ),
  66. 'menu_position' => 5,
  67. 'supports' => array( 'title', '', 'thumbnail'),
  68. 'has_archive' => true,
  69. )
  70. );
  71. //Custom texonomy
  72. register_taxonomy(
  73. 'gallery-cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  74. 'gallery', //post type name
  75. array(
  76. 'hierarchical' => true,
  77. 'label' => 'Gallery Category', //Display name
  78. 'query_var' => true,
  79. 'show_admin_column' => true,
  80. 'rewrite' => array(
  81. 'slug' => 'gallery-category', // This controls the base slug that will display before each term
  82. 'with_front' => true // Don't display the category base before
  83. )
  84. )
  85. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement