PageRenderTime 77ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/shopkeeper/inc/shortcodes/portfolio.php

https://bitbucket.org/iroshbrianskye/genteelfinal
PHP | 234 lines | 173 code | 60 blank | 1 comment | 37 complexity | 68bf306945729998823f64d2e0e01547 MD5 | raw file
Possible License(s): GPL-3.0, MIT, Apache-2.0
  1. <?php
  2. // [portfolio]
  3. function shortcode_portfolio($atts, $content = null) {
  4. global $post;
  5. $sliderrandomid = rand();
  6. extract(shortcode_atts(array(
  7. "items" => '9999',
  8. "category" => '',
  9. "show_filters" => 'yes',
  10. "order_by" => 'date',
  11. "order" => 'desc',
  12. "grid" => 'default',
  13. "portfolio_items_per_row" => '3'
  14. ), $atts));
  15. ob_start();
  16. ?>
  17. <?php
  18. if ($order_by == "alphabetical") $order_by = 'title';
  19. $args = array(
  20. 'post_status' => 'publish',
  21. 'post_type' => 'portfolio',
  22. 'posts_per_page' => $items,
  23. 'portfolio_categories' => $category,
  24. 'orderby' => $order_by,
  25. 'order' => $order,
  26. );
  27. $portfolioItems = new WP_Query( $args );
  28. while ( $portfolioItems->have_posts() ) : $portfolioItems->the_post();
  29. $terms = get_the_terms( get_the_ID(), 'portfolio_categories' ); // get an array of all the terms as objects.
  30. if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
  31. foreach($terms as $term) {
  32. $portfolio_categories_queried[$term->slug] = $term->name;
  33. }
  34. }
  35. endwhile;
  36. if ( count($portfolio_categories_queried) > 0 ) :
  37. $portfolio_categories_queried = array_unique($portfolio_categories_queried);
  38. if ($grid == "default") {
  39. $items_per_row_class = ' default_grid items_per_row_'."$portfolio_items_per_row";
  40. } else {
  41. $items_per_row_class = '';
  42. }
  43. ?>
  44. <div class="portfolio-isotope-container<?php echo esc_html($items_per_row_class);?>">
  45. <?php if ($category == "") : ?>
  46. <?php if ($show_filters == "yes") : ?>
  47. <div class="portfolio-filters">
  48. <?php
  49. if ( !empty( $portfolio_categories_queried ) && !is_wp_error( $portfolio_categories_queried ) ){
  50. echo '<ul class="filters-group list-centered">';
  51. echo '<li class="filter-item is-checked" data-filter="*">' . __("Show all", "shopkeeper") . '</li>';
  52. foreach ( $portfolio_categories_queried as $key => $value ) {
  53. echo '<li class="filter-item" data-filter=".' . $key . '">' . $value . '</li>';
  54. }
  55. echo '</ul>';
  56. }
  57. ?>
  58. </div>
  59. <?php endif; ?>
  60. <?php endif; ?>
  61. <div class="portfolio-isotope">
  62. <div class="portfolio-grid-sizer"></div>
  63. <?php
  64. $post_counter = 0;
  65. while ( $portfolioItems->have_posts() ) : $portfolioItems->the_post();
  66. $post_counter++;
  67. $related_thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'large' );
  68. $terms_slug = get_the_terms( get_the_ID(), 'portfolio_categories' ); // get an array of all the terms as objects.
  69. $term_slug_class = "";
  70. if ( !empty( $terms_slug ) && !is_wp_error( $terms_slug ) ){
  71. foreach ( $terms_slug as $term_slug ) {
  72. $term_slug_class .= $term_slug->slug . " ";
  73. }
  74. }
  75. if (get_post_meta( $post->ID, 'portfolio_color_meta_box', true )) {
  76. $portfolio_color_option = get_post_meta( $post->ID, 'portfolio_color_meta_box', true );
  77. } else {
  78. $portfolio_color_option = "none";
  79. }
  80. $portfolio_item_width = "";
  81. $portfolio_item_height = "";
  82. switch ($grid) {
  83. case "grid1":
  84. switch ($post_counter) {
  85. case (($post_counter == 1)) :
  86. $portfolio_item_width = "width2";
  87. $portfolio_item_height = "height2";
  88. break;
  89. case (($post_counter == 2)) :
  90. $portfolio_item_width = "width2";
  91. $portfolio_item_height = "";
  92. break;
  93. case (($post_counter == 7)) :
  94. $portfolio_item_width = "width2";
  95. $portfolio_item_height = "";
  96. break;
  97. case (($post_counter == 8)) :
  98. $portfolio_item_width = "width2";
  99. $portfolio_item_height = "height2";
  100. break;
  101. default :
  102. $portfolio_item_width = "";
  103. $portfolio_item_height = "";
  104. }
  105. break;
  106. case "grid2":
  107. switch ($post_counter) {
  108. case (($post_counter == 3)) :
  109. $portfolio_item_width = "width2";
  110. $portfolio_item_height = "height2";
  111. break;
  112. case (($post_counter == 8)) :
  113. $portfolio_item_width = "width2";
  114. $portfolio_item_height = "";
  115. break;
  116. case (($post_counter == 13)) :
  117. $portfolio_item_width = "width2";
  118. $portfolio_item_height = "";
  119. break;
  120. default :
  121. $portfolio_item_width = "";
  122. $portfolio_item_height = "";
  123. }
  124. break;
  125. case "grid3":
  126. switch ($post_counter) {
  127. case (($post_counter == 3)) :
  128. $portfolio_item_width = "width2";
  129. $portfolio_item_height = "";
  130. break;
  131. case (($post_counter == 8)) :
  132. $portfolio_item_width = "width2";
  133. $portfolio_item_height = "";
  134. break;
  135. case (($post_counter == 11)) :
  136. $portfolio_item_width = "width2";
  137. $portfolio_item_height = "";
  138. break;
  139. case (($post_counter == 14)) :
  140. $portfolio_item_width = "width2";
  141. $portfolio_item_height = "";
  142. break;
  143. default :
  144. $portfolio_item_width = "";
  145. $portfolio_item_height = "";
  146. }
  147. break;
  148. default:
  149. $portfolio_item_width = "";
  150. $portfolio_item_height = "";
  151. }
  152. ?>
  153. <div class="portfolio-box hidden <?php echo esc_html($portfolio_item_width); ?> <?php echo esc_html($portfolio_item_height); ?> <?php echo esc_html($term_slug_class); ?>">
  154. <a href="<?php echo get_permalink(get_the_ID()); ?>" class="portfolio-box-inner hover-effect-link" style="background-color:<?php echo esc_html($portfolio_color_option); ?>">
  155. <div class="portfolio-content-wrapper hover-effect-content">
  156. <?php if ($related_thumb[0] != "") : ?>
  157. <span class="portfolio-thumb hover-effect-thumb" style="background-image: url(<?php echo esc_url($related_thumb[0]); ?>)"></span>
  158. <?php endif; ?>
  159. <h2 class="portfolio-title hover-effect-title"><?php the_title(); ?></h2>
  160. <p class="portfolio-categories hover-effect-text"><?php echo strip_tags (get_the_term_list(get_the_ID(), 'portfolio_categories', "", ", "));?></p>
  161. </div>
  162. </a>
  163. </div>
  164. <?php endwhile; // end of the loop. ?>
  165. </div><!--portfolio-isotope-->
  166. </div><!--portfolio-isotope-container-->
  167. <?php
  168. endif;
  169. wp_reset_query();
  170. $content = ob_get_contents();
  171. ob_end_clean();
  172. return $content;
  173. }
  174. add_shortcode("portfolio", "shortcode_portfolio");