Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. <?php
  2. /**
  3. * NEWS Focus Shortcode
  4. * [kleo_news_focus name="Section name"]
  5. *
  6. * @package WordPress
  7. * @subpackage K Elements
  8. * @author SeventhQueen <themesupport@seventhqueen.com>
  9. * @since K Elements 3.0
  10. */
  11.  
  12. if ( ! function_exists( 'vc_build_loop_query' )) {
  13. $output = 'Visual composer must be installed';
  14. }
  15.  
  16. $output = $args = $my_query = $output_inside = $tabs_data = '';
  17. extract( shortcode_atts( array(
  18. 'name' => '',
  19. 'featured' => 1,
  20. 'posts_query' => '',
  21. 'el_class' => '',
  22. ), $atts ) );
  23.  
  24. if ( $featured < 1 ) {
  25. $featured = 1;
  26. }
  27.  
  28. $el_class = ( $el_class != '' ) ? 'news-focus ' . esc_attr( $el_class ) : 'news-focus';
  29.  
  30. list( $args, $my_query ) = vc_build_loop_query( $posts_query );
  31.  
  32. $main_args = $args;
  33.  
  34. $tabs_data = '[vc_tabs type="tabs" style="line" style_pills="square"]';
  35.  
  36. if ( isset( $main_args['cat'] ) ) {
  37. $cats = explode(',', $main_args['cat']);
  38. //add the section name to generate the first tab
  39. array_unshift( $cats, $name );
  40. } else {
  41. //add the section name to generate the first tab
  42. $cats = array( $name );
  43. }
  44.  
  45. $cat_count = 0;
  46.  
  47. foreach( $cats as $cat ) {
  48.  
  49. $cat_count++;
  50.  
  51. if ( $cat_count == 1 ) {
  52. $cat_name = $cat;
  53. } else {
  54. $args['cat'] = $cat;
  55. $cat_name = get_cat_name( $cat );
  56. }
  57.  
  58. query_posts( $args );
  59.  
  60. if ( have_posts() ) :
  61.  
  62. global $wp_query;
  63. if ( isset( $wp_query->post_count ) && $wp_query->post_count > 0 && $featured > $wp_query->post_count ) {
  64. $featured = $wp_query->post_count;
  65. }
  66.  
  67. $count = 0;
  68. $tabs_data .= '[vc_tab title="' . $cat_name . '"]';
  69.  
  70. $tabs_data .= '<div class="row">';
  71. $tabs_data .= '<div class="col-sm-6">';
  72. $tabs_data .= '<div class="posts-listing standard-listing with-meta inline-meta">';
  73.  
  74. while ( have_posts() ) : the_post();
  75.  
  76. $count++;
  77.  
  78. $kleo_post_format = get_post_format();
  79.  
  80. //Left side thumb
  81. if ( $count <= $featured ) {
  82.  
  83. ob_start();
  84. ?>
  85.  
  86. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  87. <div class="post-content animated animate-when-almost-visible el-appear">
  88.  
  89. <div class="article-media clearfix">
  90. <?php echo kleo_get_post_media( $kleo_post_format ); ?>
  91. </div>
  92.  
  93. <h3 class="post-title entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
  94.  
  95. <div class="article-meta">
  96. <span class="post-meta">
  97. <?php kleo_entry_meta();?>
  98. </span>
  99. </div>
  100.  
  101. <div class="entry-summary">
  102. <?php if ( ! in_array( $kleo_post_format, array('status', 'quote', 'link') ) ): ?>
  103. <?php echo kleo_excerpt(); ?>
  104. <?php else : ?>
  105. <?php the_content();?>
  106. <?php endif;?>
  107. </div><!-- .entry-summary -->
  108.  
  109. </div>
  110. </article>
  111.  
  112. <?php if ( $count == $featured ) : ?>
  113.  
  114. </div> <!-- .posts-listing -->
  115. </div> <!-- .col-sm-6 -->
  116.  
  117. <div class="col-sm-6">
  118. <div class="posts-listing left-thumb-listing">
  119.  
  120. <?php endif; ?>
  121.  
  122. <?php
  123. $tabs_data .= ob_get_clean();
  124.  
  125. } else {
  126. ob_start();
  127. ?>
  128.  
  129. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  130. <div class="post-content animated animate-when-almost-visible el-appear">
  131.  
  132. <div class="article-media">
  133. <?php echo kleo_get_post_media( $kleo_post_format, array( 'media_width' => 220, 'media_height' => 192 ) ); ?>
  134. </div>
  135.  
  136. <div class="post-date"><?php the_date();?></div>
  137.  
  138. <h3 class="post-title entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
  139.  
  140. </div>
  141. </article>
  142.  
  143. <?php
  144. $tabs_data .= ob_get_clean();
  145. }
  146.  
  147. endwhile;
  148.  
  149. $tabs_data .= '</div>';
  150. $tabs_data .= '</div>';
  151. $tabs_data .= '</div>';
  152.  
  153. $tabs_data .= '[/vc_tab]';
  154.  
  155. endif;
  156.  
  157. // Reset Query
  158. wp_reset_query();
  159.  
  160. }
  161.  
  162.  
  163. $tabs_data .= '[/vc_tabs]';
  164.  
  165. $output_inside .= do_shortcode( $tabs_data );
  166.  
  167. $output .= "\n\t"."<div class=\"{$el_class}\">{$output_inside}</div>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement