vc-portfolios-post.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /*------------------------------------------------------*/
  3. /* taskereasy Heading
  4. /*------------------------------------------------------*/
  5. vc_map(array(
  6. "name" => esc_html__("Portfolio Posts", 'taskereasy'),
  7. "base" => "taskereasy_portfolios_post",
  8. 'icon' => get_template_directory_uri() . '/assets/images/favicon-icon/shortcode-icon.png',
  9. "class" => "",
  10. "description" => esc_html__("Add taskereasy portfolios post type", 'taskereasy'),
  11. "category" => esc_html__('Taskereasy Shortcodes', 'taskereasy'),
  12. "params" => array(
  13. array(
  14. "type" => "dropdown",
  15. "heading" => esc_html__("Post Columns", 'taskereasy'),
  16. "param_name" => "post_coloumns",
  17. "value" => array('Two with big column' => '3', 'Three with big column' => '4'),
  18. ),
  19. array(
  20. 'type' => 'css_editor',
  21. 'heading' => esc_html__( 'CSS', 'taskereasy' ),
  22. 'param_name' => 'custom_design',
  23. 'group' => esc_html__( 'Design options', 'taskereasy' ),
  24. )
  25. )
  26. ));
  27. add_shortcode( 'taskereasy_portfolios_post', function($atts, $content = null) {
  28. extract(shortcode_atts(array(
  29. 'blog_post' => '',
  30. 'post_coloumns' => '3',
  31. 'post_style' => 'grid',
  32. 'custom_design' => '',
  33. ), $atts));
  34. $custom_design = vc_shortcode_custom_css_class( $custom_design, ' ' );
  35. $postcoloumns = html_entity_decode(vc_value_from_safe($post_coloumns, true));
  36. $output = '';
  37. $output .= '<div class="portfolio-list">';
  38. $col_num = ($postcoloumns == '3')? '6' : '4';
  39. $args = array(
  40. 'post_type' => 'portfolios',
  41. 'orderby' => 'date',
  42. 'posts_per_page' => $postcoloumns-1,
  43. 'offset' => 0,
  44. );
  45. $the_query = new WP_Query( $args );
  46. $output .= '<div class="row">';
  47. if ( $the_query->have_posts() ) :
  48. global $post;
  49. while ( $the_query->have_posts() ) : $the_query->the_post();
  50. $output .='
  51. <div class="col-lg-'.$col_num.'">
  52. <div class="portfolio-box">';
  53. if(has_post_thumbnail()){
  54. $output .= '<div class="porfolio-img"> '.get_the_post_thumbnail().' </div>';
  55. }
  56. $output .= '<div class="portfolio-heading">';
  57. $term_list = wp_get_post_terms($post->ID, 'portfoliocategories', array("fields" => "all"));
  58. //$output .= print_r($term_list);
  59. $count = count($term_list);
  60. foreach($term_list as $term){
  61. $output .= ' <div class="portfolio-caty"><a href="'.get_term_link($term->slug, "portfoliocategories").'" >'.$term->name.'</a></div> ';
  62. }
  63. $output .= '<h3><a href="'.get_the_permalink().'">'.get_the_title().'</a></h3></div>
  64. </div>
  65. </div>';
  66. endwhile;
  67. wp_reset_postdata();
  68. else :
  69. $output .= '<p>'.esc_html__( 'Sorry, no posts matched your criteria.', 'taskereasy' ) .'</p>';
  70. endif;
  71. $output .= '</div>';
  72. //full portfolio
  73. $full_args = array(
  74. 'post_type' => 'portfolios',
  75. 'posts_per_page' => 1,
  76. 'orderby' => 'date',
  77. 'offset' => $postcoloumns-1,
  78. );
  79. $the_query = new WP_Query( $full_args );
  80. if ( $the_query->have_posts() ) {
  81. global $post;
  82. $output .= '<div class="full-portfolio">
  83. <div class="row">';
  84. while ( $the_query->have_posts() ) { $the_query->the_post();
  85. $output .= '<div class="col-lg-8">';
  86. if(has_post_thumbnail()){
  87. $output .= '<div class="porfolio-img"> '.get_the_post_thumbnail().' </div>';
  88. }
  89. $output .= '</div>
  90. <div class="col-lg-4">
  91. <div class="portfolio-col">';
  92. $term_list = wp_get_post_terms($post->ID, 'portfoliocategories', array("fields" => "all"));
  93. //$output .= print_r($term_list);
  94. $count = count($term_list);
  95. foreach($term_list as $term){
  96. $output .= ' <div class="portfolio-caty"><a href="'.get_term_link($term->slug, "portfoliocategories").'" >'.$term->name.'</a></div> ';
  97. }
  98. $output .= '<h3><a href="'.get_the_permalink().'">'.get_the_title().'</a></h3>
  99. <p>'.taskereasy_custom_excerpt_length(20).'</p>
  100. <a href="'.get_the_permalink().'" class="btn btn-md">'.esc_html__('Read More', 'taskereasy').'</a> </div>
  101. </div>';
  102. } //end while
  103. wp_reset_postdata();
  104. $output .= '</div>
  105. </div>';
  106. } // end if posts
  107. else {
  108. $output .= '<p>'.esc_html__( 'Sorry, no posts matched your criteria.', 'taskereasy' ) .'</p>';
  109. }
  110. $output .= '</div>';
  111. return $output;
  112. });