<?php
/*
* Add-on Name: CP Addons For Visual Composer
* Add-on URI: http://dev.crunchpress.com
*/
if(!class_exists("what_we_do_missions")){
class what_we_do_missions{
static $add_plugin_script;
function __construct(){
add_action("init",array($this,"what_we_do_missions_init"));
add_shortcode('what_we_do_missions',array($this,'what_we_do_missions_shortcode'));
}
function what_we_do_missions_init(){
if(function_exists("vc_map")){
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'date',
'order' => 'DESC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$categories = get_categories( $args );
$taxonomies = get_taxonomies();
if($categories){
$categoryArray[0] = "All";
foreach($categories as $category_list){
$categoryArray[$category_list->term_id] = $category_list->name;
}
} else {
$categoryArray = array();
}
vc_map( array(
"base" => "what_we_do_missions",
"name" => __( "What We Do - Missions", "js_composer" ),
"class" => "what_we_do_missions_class",
"icon" => get_template_directory_uri() . "/assets/images/cp_icon.PNG",
"category" => __( 'CrunchPress', 'js_composer' ),
"params" => array(
array(
"type" => "textfield",
"holder" => "p",
"class" => "",
"heading" => __( "Element Caption", "js_composer" ),
"param_name" => "element_caption",
"description" => __( "Enter Element Caption, Leave Blank To Remove i.e Organizing for Action ", "js_composer" )
),
array(
"type" => "textfield",
"holder" => "p",
"class" => "",
"heading" => __( "Element Title", "js_composer" ),
"param_name" => "element_title",
"description" => __( "Enter Element Title Here, Leave Blank To Remove i.e What We Do?", "js_composer" )
),
array(
'type' => 'textarea_html',
"holder" => "p",
'heading' => __( 'Description', 'js_composer' ),
'param_name' => 'content',
'description' => __( 'Add Description For Element.', 'js_composer' ),
),
array(
'type' => 'vc_link',
"holder" => "p",
'heading' => __( 'Read More (Link)', 'js_composer' ),
'param_name' => 'readmore_url_btn',
'description' => __( 'Add Text & Link For Button, Leave Blank To Remove', 'js_composer' ),
),
array(
"type" => "textfield",
"holder" => "p",
"class" => "",
"heading" => __( "Missions Heading", "js_composer" ),
"param_name" => "secondary_title",
"description" => __( "Enter Title For Missions and Visions, Leave Blank To Remove", "js_composer" )
),
array(
"type" => "dropdown",
"holder" => "p",
"heading" => __( "Select Post Category", "js_composer" ),
"param_name" => "category_name",
"value" => $categoryArray,
"description" => __( "Select Category From The Dropdown", "js_composer" )
),
array(
"type" => "textfield",
"holder" => "p",
"class" => "",
"heading" => __( "Posts Count", "js_composer" ),
"param_name" => "num_posts",
"description" => __( "Enter Count of Posts To Fetch, Leave Blank To Remove", "js_composer" )
),
array(
"type" => "textfield",
"holder" => "p",
"class" => "",
"heading" => __( "Excerpt Length", "js_composer" ),
"param_name" => "num_characters",
"description" => __( "Enter Excerpt Content Length Here i.e 79", "js_composer" )
),
array(
"type" => "dropdown",
"holder" => "p",
"heading" => __( "Extra Bottom Spacing", "js_composer" ),
"param_name" => "remove_space",
"value" => array( __( 'Add Extra Space', 'js_composer' ) => 'add',
__( 'Remove Extra Space', 'js_composer' ) => 'remove',
),
"description" => __( "Add Extra Bottom Space", "js_composer" )
),
)
)
);
}
}
function what_we_do_missions_shortcode( $atts, $content = null ) {
$result = shortcode_atts( array(
'element_title' => '',
'element_caption' => '',
'secondary_title' => '',
'readmore_url_btn' => '',
'category_name' => '',
'num_posts' => '2',
'num_characters' => '79',
'remove_space' => 'add',
), $atts );
extract( $result );
global $wpdb,$post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if($category_name != 'All' && !empty($category_name)){
$term = '';
$term = get_term_by('name', $category_name, 'category');
if(is_object($term)){
$category_id = $term->term_id;
$stack_cat_all = array('tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => $category_id,
'field' => 'term_id',
)
),
);
$args = array(
'post_type' => 'post',
'posts_per_page' => $num_posts,
'ignore_sticky_posts' => 1,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => $category_id,
'field' => 'term_id',
)
),
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
);
}else{
$args = array(
'post_type' => 'post',
'ignore_sticky_posts' => 1,
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => $num_posts,
'orderby' => 'date',
'order' => 'DESC'
);
}
}else{
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'paged' => $paged,
'posts_per_page' => $num_posts,
'orderby' => 'date',
'order' => 'DESC'
);
}
query_posts($args);
/* Build Link First */
$readmore_url_btn = vc_build_link( $readmore_url_btn );
if(!empty($readmore_url_btn['url'])){ $readmore_url_link = esc_url($readmore_url_btn['url']); }else{ $readmore_url_link = ''; }
if(!empty($readmore_url_btn['title'])){ $readmore_text = esc_attr($readmore_url_btn['title']); }else{ $readmore_text = ''; }
if($remove_space == 'add'){ $space_class = 'bottom-spac450';}else{ $space_class = ''; }
/* HTML Markup */
$output = '
<section>
<div class="spacing '.$space_class.'">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12 col-lg-6">
<div class="about-us">
<h2 itemprop="headline">
<span class="theme-clr">'.$element_caption.'</span> '.$element_title.'</h2>
'.wpautop($content).'
<a class="brd-rd33 theme-btn big" href="'.$readmore_url_link.'" title="" itemprop="url">'.$readmore_text.'</a>
</div><!-- About Us -->
</div>
<div class="col-md-6 col-sm-12 col-lg-6">
<div class="our-missions">
<h5 itemprop="headline">'.$secondary_title.'</h5>
<div class="missions-list remove-ext3">';
/* Loop Begins */
if ( have_posts() ) {
while ( have_posts() ) { the_post(); global $post;
/* Content */
if (strlen(get_the_content()) > $num_characters){
$post_content = mb_substr(strip_tags(get_the_content()), 0, $num_characters).'...';
}else{
$post_content = strip_tags(get_the_content());
}
$output .= '
<div class="missions-box brd-rd5">
<a class="brd-rd5" href="'.get_the_permalink().'" title="'.get_the_title().'" itemprop="url">'.get_the_post_thumbnail($post->ID, array(115,121)).'</a>
<div class="mission-box-info">
<h6 itemprop="headline"><a href="'.get_the_permalink().'" title="'.get_the_title().'" itemprop="url">'.get_the_title().'</a></h6>
<p itemprop="description">'.$post_content.'</p>
</div>
</div>';
} /* endwhile */ wp_reset_query();
} /*endif */
$output .= '
</div>
</div>
</div>
</div>
</div>
</div>
</section>';
return $output;
} /* end of function */
}
new what_we_do_missions;
if(class_exists('WPBakeryShortCode'))
{
class WPBakeryShortCode_what_we_do_missions extends WPBakeryShortCode {
}
}
}