vc-blog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*------------------------------------------------------*/
  3. /* taskereasy Heading
  4. /*------------------------------------------------------*/
  5. vc_map(array(
  6. "name" => esc_html__("Blog Posts", 'taskereasy'),
  7. "base" => "taskereasy_blog_post",
  8. 'icon' => get_template_directory_uri() . '/assets/images/favicon-icon/shortcode-icon.png',
  9. "class" => "",
  10. "description" => esc_html__("Add taskereasy blog post type", 'taskereasy'),
  11. "category" => esc_html__('Taskereasy Shortcodes', 'taskereasy'),
  12. "params" => array(
  13. array(
  14. "type" => "dropdown",
  15. "heading" => esc_html__("Style", 'taskereasy'),
  16. "param_name" => "style",
  17. "value" => array('Style 1' => 'style_1', 'Style 2' => 'style_2'),
  18. ),
  19. array(
  20. "type" => "dropdown",
  21. "heading" => esc_html__("Post Columns", 'taskereasy'),
  22. "param_name" => "post_coloumns",
  23. "value" => array('Three columns' => '3', 'Four columns' => '4'),
  24. ),
  25. array(
  26. 'type' => 'css_editor',
  27. 'heading' => esc_html__( 'CSS', 'taskereasy' ),
  28. 'param_name' => 'custom_design',
  29. 'group' => esc_html__( 'Design options', 'taskereasy' ),
  30. )
  31. )
  32. ));
  33. add_shortcode( 'taskereasy_blog_post', function($atts, $content = null) {
  34. extract(shortcode_atts(array(
  35. 'style' => 'style_1',
  36. 'post_coloumns' => '3',
  37. 'custom_design' => '',
  38. ), $atts));
  39. $custom_design = vc_shortcode_custom_css_class( $custom_design, ' ' );
  40. $postcoloumns = html_entity_decode(vc_value_from_safe($post_coloumns, true));
  41. $output = '';
  42. $args = array(
  43. 'post_type' => 'post',
  44. 'orderby' => 'date',
  45. 'order' => 'desc',
  46. 'posts_per_page' => $postcoloumns,
  47. );
  48. $the_query = new WP_Query( $args );
  49. $output .= '<div class="row '.$custom_design.'">';
  50. if ( $the_query->have_posts() ) :
  51. global $post;
  52. while ( $the_query->have_posts() ) : $the_query->the_post();
  53. $col_num = ($postcoloumns == 4)? '3' : '4';
  54. $output .='
  55. <article class="col-lg-'.esc_attr($col_num).'">';
  56. if($style == 'style_1'){
  57. //Style 1
  58. $output.=
  59. '<div class="post-wrap p-0">
  60. <div class="post-img dark-shadow">';
  61. if(has_post_thumbnail()){
  62. $output .= '<a href="'.get_the_permalink().'">'.get_the_post_thumbnail().'</a>';
  63. }
  64. $output .=
  65. '</div>
  66. <div class="post-info">
  67. <h4><a href="'.get_the_permalink().'">'.get_the_title().'</a></h4>
  68. </div>
  69. </div>';
  70. }else{
  71. //Style 2
  72. $output.=
  73. '<div class="offer-4-container">';
  74. if(has_post_thumbnail()){
  75. $output .= '<a href="'.get_the_permalink().'">'.get_the_post_thumbnail().'</a>';
  76. }
  77. $output.='
  78. <div class="offer-container">
  79. <h4><a href="'.get_the_permalink().'">'.get_the_title().'</a></h4>
  80. <p>'.taskereasy_custom_excerpt_length(10).'</p>
  81. </div>
  82. <a href="'.get_the_permalink().'" class="btn">'.esc_html__("Read More", "taskereasy").'</a>
  83. </div>';
  84. }
  85. $output.='
  86. </article>';
  87. endwhile;
  88. wp_reset_postdata();
  89. else :
  90. $output .= '<p>'.esc_html__( 'Sorry, no posts matched your criteria.', 'taskereasy' ) .'</p>';
  91. endif;
  92. $output .= '</div>';
  93. return $output;
  94. });