Advertisement
Guest User

Untitled

a guest
May 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.70 KB | None | 0 0
  1. /*
  2. ----------------------------------------------------------------------------------------------------
  3. [forqy-menu section_id="1"]
  4. ----------------------------------------------------------------------------------------------------
  5. */
  6.  
  7. if ( ! function_exists( 'forqy_shortcode_menu' ) ) {
  8.  
  9.     function forqy_shortcode_menu( $atts, $content = null ) {
  10.         // Type
  11.         $type = 'menu';
  12.         // Taxonomy
  13.         $taxonomy = 'section';
  14.  
  15.         $atts = shortcode_atts(
  16.             array(
  17.                 'section_id' => '1',
  18.             ),
  19.             $atts
  20.         );
  21.         ?>
  22.  
  23.         <?php
  24.         $count = 1;
  25.  
  26.         /**
  27.          * Get Terms
  28.          */
  29.         $args  = array(
  30.             'orderby'    => 'none',
  31.             'order'      => 'ASC',
  32.             'hide_empty' => 1,
  33.             'parent'     => 0,
  34.             'include'    => $atts['section_id']
  35.         );
  36.         $terms = get_terms( $taxonomy, $args );
  37.         ?>
  38.  
  39.         <?php if ( $terms ) { ?>
  40.             <?php foreach ( $terms as $term ) { ?>
  41.  
  42.                 <?php
  43.                 /**
  44.                  * Terms Query
  45.                  */
  46.                 $args  = array(
  47.                     'post_type' => $type,
  48.                     'tax_query' => array(
  49.                         array(
  50.                             'taxonomy'         => $taxonomy,
  51.                             'terms'            => $atts['section_id'],
  52.                             'field'            => 'term_id',
  53.                             'include_children' => 0
  54.                         )
  55.                     ),
  56.                 );
  57.                 $query = new WP_Query( $args );
  58.                 ?>
  59.  
  60.                 <section class="fy-term-item fy-term-item-<?php echo esc_attr( $count ); ?>">
  61.  
  62.                     <header class="fy-term-header js-reveal-container">
  63.                         <h2 class="js-reveal"><?php echo apply_filters( 'translate_text', esc_attr( $term->name ) ); ?></h2>
  64.  
  65.                         <?php if ( ! empty( $term->description ) ) { ?>
  66.                             <div class="fy-term-description js-reveal">
  67.                                 <?php echo apply_filters( 'translate_text', wp_kses( $term->description, array(
  68.                                     'a'      => array(
  69.                                         'href'   => array(),
  70.                                         'target' => array()
  71.                                     ),
  72.                                     'br'     => array(),
  73.                                     'em'     => array(),
  74.                                     'strong' => array()
  75.                                 ) ) ); ?>
  76.                             </div>
  77.                         <?php } ?>
  78.                     </header>
  79.  
  80.                     <?php if ( $query->have_posts() ) { ?>
  81.                         <div
  82.                             class="fy-flex-container fy-flex-container-stretch fy-flex-gutter-large js-reveal-container">
  83.                             <?php while ( $query->have_posts() ) { ?>
  84.                                 <?php $query->the_post(); ?>
  85.  
  86.                                 <div
  87.                                     class="fy-flex-column-33 fy-flex-column-tablet-100">
  88.                                     <?php get_template_part( 'content', $type ); ?>
  89.                                 </div>
  90.  
  91.                             <?php } ?>
  92.                         </div>
  93.                     <?php } ?>
  94.  
  95.                     <?php
  96.                     /**
  97.                      * Get Children
  98.                      */
  99.  
  100.                     $args_children = array(
  101.                         'taxonomy' => $taxonomy,
  102.                         'child_of' => $atts['section_id'],
  103.                         'order'    => 'ASC',
  104.                         'orderby'  => 'date',
  105.                     );
  106.                     $children      = get_terms( $args_children );
  107.                     ?>
  108.  
  109.                     <?php foreach ( $children as $child ) { ?>
  110.  
  111.                         <?php
  112.                         /**
  113.                          * Child Query
  114.                          */
  115.                         $args_child  = array(
  116.                             'post_type'           => $type,
  117.                             'tax_query'           => array(
  118.                                 array(
  119.                                     'taxonomy' => $taxonomy,
  120.                                     'terms'    => $child->slug,
  121.                                     'field'    => 'slug'
  122.                                 )
  123.                             ),
  124.                             'post_status'         => 'publish',
  125.                             'order'               => 'ASC',
  126.                             'orderby'             => 'date',
  127.                             'ignore_sticky_posts' => 1,
  128.                             'posts_per_page'      => - 1
  129.                         );
  130.                         $query_child = new WP_Query( $args_child );
  131.                         ?>
  132.  
  133.                         <?php if ( $query_child->have_posts() ) { ?>
  134.                             <header class="fy-child-header">
  135.                                 <h3 class="fy-padding-top-0"><?php echo apply_filters( 'translate_text', esc_attr( $child->name ) ); ?></h3>
  136.  
  137.                                 <?php if ( ! empty( $child->description ) ) { ?>
  138.                                     <div class="fy-child-description">
  139.                                         <?php echo apply_filters( 'translate_text', wp_kses( $child->description, array(
  140.                                             'a'      => array(
  141.                                                 'href'   => array(),
  142.                                                 'target' => array()
  143.                                             ),
  144.                                             'br'     => array(),
  145.                                             'em'     => array(),
  146.                                             'strong' => array()
  147.                                         ) ) ); ?>
  148.                                     </div>
  149.                                 <?php } ?>
  150.                             </header>
  151.  
  152.                             <div class="fy-flex-container fy-flex-container-stretch fy-flex-gutter-large">
  153.                                 <?php while ( $query_child->have_posts() ) { ?>
  154.                                     <?php $query_child->the_post(); ?>
  155.  
  156.                                     <div
  157.                                         class="<?php if ( is_active_sidebar( $type ) ) { ?> fy-flex-column-100 <?php } else { ?> fy-flex-column-50<?php } ?> fy-flex-column-tablet-100">
  158.                                         <?php get_template_part( 'content', $type ); ?>
  159.                                     </div>
  160.  
  161.                                 <?php } ?>
  162.                             </div>
  163.                         <?php } ?>
  164.                     <?php } ?>
  165.  
  166.                 </section>
  167.  
  168.                 <?php $count ++; ?>
  169.             <?php } ?>
  170.  
  171.             <?php wp_reset_postdata(); ?>
  172.         <?php } else { ?>
  173.  
  174.             <?php get_template_part( 'content', 'empty' ); ?>
  175.  
  176.         <?php } ?>
  177.  
  178.         <?php
  179.  
  180.     }
  181.  
  182.     add_shortcode( 'forqy-menu', 'forqy_shortcode_menu' );
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement