RUSSEL86

Gallery sortcode TAB title & category for different gallery

Jun 28th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.93 KB | None | 0 0
  1. add_action( 'init', 'my_theme_custom_post' );
  2. function my_theme_custom_post() {
  3.     register_post_type( 'gallery-items',
  4.         array(
  5.             'labels' => array(
  6.                 'name' => __( 'Gallery Photo', 'wheelmasters' ),
  7.                 'all_items'     => __( 'All Gallery Photo', 'wheelmasters' ),
  8.                 'singular_name' => __( 'Gallery Photo', 'wheelmasters' ),
  9.                 'add_new'       => __( 'Add New Gallery', 'wheelmasters' ),
  10.                 'add_new_item'  => __( 'Add New Gallery', 'wheelmasters' )
  11.             ),
  12.             'public' => true,
  13.             'publicly_queryable' => true,
  14.             'menu_icon' => 'dashicons-schedule',
  15.             'supports' => array('title'),
  16.             'has_archive' => true,
  17.             'rewrite' => array('slug' => 'gallery-photo'),
  18.         )
  19.     );
  20.    
  21. }
  22.  
  23. function my_custom_post_taxonomy() {
  24.     register_taxonomy(
  25.         'gallery_cat',
  26.         'gallery-items',  
  27.         array(
  28.             'hierarchical'          => true,
  29.             'label'                 => 'Gallery Category',
  30.             'query_var'             => true,
  31.             'show_admin_column'     => true,
  32.             'rewrite'               => array(
  33.                 'slug'    => 'gallery-cat',
  34.                 'with_front'  => true
  35.                 )
  36.             )
  37.     );
  38. }
  39. add_action( 'init', 'my_custom_post_taxonomy');
  40.  
  41.  
  42.    
  43.  
  44. function kingrussel_scripts() {
  45.     global $wp_styles;
  46.     wp_enqueue_script( 'script-jegpop', '//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js', array('jquery'), '1.1.0', false );
  47.     wp_register_style( 'style-pop', '//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css', array(), '1.1.0', 'all' );
  48.     wp_enqueue_style( 'style-pop');
  49.    
  50. }
  51. add_action( 'wp_enqueue_scripts', 'kingrussel_scripts' );  
  52.  
  53.      
  54. function krproduct_shortcode($atts){
  55.    
  56.     ob_start();
  57.    
  58.    
  59.     extract( shortcode_atts( array(
  60.         'cat' => '',
  61.     ), $atts, 'jeg_gallery' ) );
  62.    
  63.     ?>
  64.  
  65.  
  66.  <style type="text/css">
  67. .hire_tab_main_area{
  68.     margin-bottom: 10px;
  69.     float: left;    width: 100%;
  70. }
  71. .hire_tab_list{
  72.     float: left;
  73.     width: 100%;
  74.     margin-right: 1%;
  75. }
  76. .hire_tab_list ul.tabs{text-align:center}
  77. .hire_tab_list ul.tabs li{
  78.     display: inline-block;
  79.     color: #000;    padding: 10px 20px;
  80.    
  81.    
  82. }
  83. .hire_tab_content{
  84.     float: left;
  85.     width: 100%;    margin: 10px 0;
  86. }
  87. .hire_tab_content .tab-content ul {}
  88.  
  89. .hire_tab_content .tab-content ul li {
  90.     float: left;
  91.     width: 25%;
  92.     padding: 10px;    margin: 0;min-height: 250px;
  93. }
  94.  
  95. .hire_tab_content .tab-content ul li:before {
  96.     display: none;
  97. }
  98. .hire_tab_content .tab-content{}
  99. .tab_content_title{}
  100. .tab_content_title h1{}
  101.  
  102. ul.tabs{
  103.     margin: 0px;
  104.     padding: 0px;
  105.     list-style: none;
  106. }
  107. ul.tabs li{
  108.     background: none;
  109.     color: #fff;
  110.     display: inline-block;
  111.     padding: 0 5px;
  112.     cursor: pointer;
  113.     border: 1px solid;
  114. }
  115. .hire_tab_list ul.tabs li:before{display:none}
  116. ul.tabs li.current{
  117.         background: #9f2141;
  118.     color: #fff;border: 1px solid #cc9f53;
  119. }
  120.  
  121. .tab-content{
  122.     display: none;
  123.     padding: 0 5px;
  124.     line-height: 20px;
  125. }
  126.  
  127. .tab-content.current{
  128.     display: inherit;
  129. }
  130.  
  131.  
  132.  
  133. /* Mobile Layout: 320px. */
  134. @media only screen and (max-width: 767px) {
  135. .hire_tab_content .tab-content ul li {    width: 100%;   padding: 0;   margin: 0;   min-height: auto;    margin-bottom: 10px;}
  136. .hire_tab_list ul.tabs li {    padding: 6px 10px;    font-size: 12px;}
  137.  
  138.  
  139. }
  140.  
  141.  
  142. </style>
  143.  
  144.    
  145.         <div class="hire_tab_main_area">
  146.             <div class="hire_tab_list">
  147.                 <ul class="tabs">
  148.                
  149.                 <?php $ctr = 0;
  150.                     $my_query = new WP_Query(array(
  151.                         'post_type' => 'gallery-items',
  152.                         'posts_per_page' => -1,
  153.                         'order' => 'ASC',
  154.                         'gallery_cat' => $cat,
  155.                     ));?>
  156.                    
  157.                     <li class="tab-link current" data-tab="tab-all">All</li>
  158.                    
  159.                     <?php
  160.                     if($my_query->have_posts()):
  161.                     while($my_query->have_posts()): $my_query->the_post();
  162.                     //$class = $ctr == 0 ? ' current' : '';
  163.                     ?>
  164.                    
  165.                     <li class="tab-link" data-tab="tab-<?php the_ID(); ?>"><?php the_title();?></li>
  166.                    
  167.                        <?php $ctr++;
  168.                     endwhile; endif; wp_reset_query(); ?>
  169.                 </ul>
  170.             </div>
  171.             <div class="hire_tab_content">
  172.            
  173.             <?php
  174.                     $taball_query = new WP_Query(array(
  175.                         'post_type' => 'gallery-items',
  176.                         'posts_per_page' => -1,
  177.                         'order' => 'ASC',
  178.                         'gallery_cat' => $cat,
  179.                     ));?>
  180.                     <div id="tab-all" class="tab-content current">
  181.                     <?php
  182.                     if($taball_query->have_posts()):
  183.                     while($taball_query->have_posts()): $taball_query->the_post();
  184.                      
  185.                     ?>
  186.                    
  187.                
  188.                
  189.                    
  190.                     <?php  
  191.                         $images = get_field('upload_your_images_here');
  192.                    
  193.                         if( $images ): ?>
  194.                         <ul class="gallery">
  195.                             <?php foreach( $images as $image ): ?>
  196.                                <li class="gallery-popup">
  197.                                     <a class="popup-link" href="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>">
  198.                                          <img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
  199.                                          <p style="text-align:center"><?php echo $image['title']; ?></p>
  200.                                     </a>
  201.                                </li>    
  202.                                
  203.                             <?php endforeach; ?>
  204.                         </ul>
  205.                     <?php endif; ?>
  206.                
  207.                
  208.                 <?php endwhile; endif; wp_reset_query();?>
  209.             </div>
  210.             <?php $ctrcont = 0;
  211.                     $tab_query = new WP_Query(array(
  212.                         'post_type' => 'gallery-items',
  213.                         'posts_per_page' => -1,
  214.                         'order' => 'ASC',
  215.                         'gallery_cat' => $cat,
  216.                     ));
  217.                     if($tab_query->have_posts()):
  218.                     while($tab_query->have_posts()): $tab_query->the_post();
  219.                     //$class = $ctrcont == 0 ? ' current' : '';
  220.                     ?>
  221.                    
  222.                 <div id="tab-<?php the_ID(); ?>" class="tab-content">
  223.                
  224.                    
  225.                     <?php
  226.  
  227. $images = get_field('upload_your_images_here');
  228.  
  229.     if( $images ): ?>
  230.     <ul class="gallery">
  231.         <?php foreach( $images as $image ): ?>
  232.            <li class="gallery-popup">
  233.                 <a class="popup-link" href="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>">
  234.                      <img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
  235.                      <p style="text-align:center"><?php echo $image['title']; ?></p>
  236.                 </a>
  237.            </li>    
  238.            
  239.         <?php endforeach; ?>
  240.     </ul>
  241. <?php endif; ?>
  242.                 </div>
  243.                
  244.                 <?php $ctrcont++;
  245.                     endwhile; endif; wp_reset_query();?>
  246.                
  247.             </div>
  248.         </div>
  249.        
  250.        
  251.        
  252. <script type="text/javascript">
  253. jQuery('ul.tabs li').click(function(){
  254.         var tab_id = jQuery(this).attr('data-tab');
  255.  
  256.         jQuery('ul.tabs li').removeClass('current');
  257.         jQuery('.tab-content').removeClass('current');
  258.  
  259.         jQuery(this).addClass('current');
  260.         jQuery("#"+tab_id).addClass('current');
  261.     })
  262. jQuery('ul.gallery').each(function() { // the containers for all your galleries
  263.     jQuery(this).magnificPopup({
  264.         delegate: 'a', // the selector for gallery item
  265.         type: 'image',
  266.         gallery: {
  267.           enabled:true
  268.         }
  269.     });
  270. });
  271. </script>
  272.    
  273.          <?php return ob_get_clean();
  274. }
  275. add_shortcode('jeg_gallery', 'krproduct_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment