Created
December 2, 2017 19:20
-
-
Save Galibri/07240f30214c396f54049e1eabefb69a to your computer and use it in GitHub Desktop.
My KC shortcodes with styling options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//section title shortcode | |
function apbd_industry_section_title_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'subtitle' => '', | |
'title' => '', | |
'description' => '' | |
), $atts) ); | |
extract($atts); | |
// Create master class, return as an array | |
$master_class = apply_filters( 'kc-el-class', $atts ); | |
// Add new custom class to master class | |
$master_class[] = 'kc-raw-code'; | |
$apbd_industry_section_title_shortcode = '<div class="apbd-industry-section-title ' . esc_attr( $css_class ) . esc_attr( implode( " ", $master_class ) ) .'">'; | |
if( !empty($subtitle) ){ | |
$apbd_industry_section_title_shortcode .= '<h4>' . esc_html( $subtitle ) .'</h4>'; | |
} | |
if( !empty($title) ){ | |
$apbd_industry_section_title_shortcode .= '<h2>' . esc_html( $title ) .'</h2>'; | |
} | |
if( !empty($description) ){ | |
$apbd_industry_section_title_shortcode .= '' . wpautop( esc_html( $description ) ) . ''; | |
} | |
$apbd_industry_section_title_shortcode .= '</div>'; | |
return $apbd_industry_section_title_shortcode; | |
} | |
add_shortcode('apbd_industry_section_title', 'apbd_industry_section_title_shortcode'); | |
//service box shortcode | |
function apbd_industry_service_box_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'icon_type' => 1, | |
'fa_icon' => 'fa fa-star', | |
'img_icon' => '', | |
'title' => '', | |
'description' => '' | |
), $atts) ); | |
extract($atts); | |
// Create master class, return as an array | |
$master_class = apply_filters( 'kc-el-class', $atts ); | |
// Add new custom class to master class | |
$master_class[] = 'kc-raw-code'; | |
$apbd_industry_service_box_markup = '<div class="apbd-industry-service-box ' . esc_attr( implode( " ", $master_class ) ) . '">'; | |
if($icon_type == 1){ | |
$apbd_industry_service_box_markup .= '<div class="apbd-industry-icon"> | |
<i class="' . esc_attr( $fa_icon ) .'"></i> | |
</div>'; | |
}else { | |
$service_box_img_id = wp_get_attachment_image_src( $img_icon, 'thumbnail' ); | |
$apbd_industry_service_box_markup .= '<div class="apbd-industry-img-icon"> | |
<img src="' . esc_url( $service_box_img_id[0] ) .'" alt="' . esc_html( $title ) .'" /> | |
</div>'; | |
} | |
if( !empty($title) ){ | |
$apbd_industry_service_box_markup .= '<h2>' . esc_html( $title ) .'</h2>'; | |
} | |
if( !empty($description) ){ | |
$apbd_industry_service_box_markup .= '' . wpautop( esc_html( $description ) ) . ''; | |
} | |
$apbd_industry_service_box_markup .= '</div>'; | |
return $apbd_industry_service_box_markup; | |
} | |
add_shortcode('apbd_industry_service_box', 'apbd_industry_service_box_shortcode'); | |
//counter box | |
function apbd_industry_counter_box_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'icon_type' => 1, | |
'fa_icon' => 'fa fa-star', | |
'img_icon' => '', | |
'sub_title' => '', | |
'counter' => '' | |
), $atts) ); | |
extract($atts); | |
// Create master class, return as an array | |
$master_class = apply_filters( 'kc-el-class', $atts ); | |
// Add new custom class to master class | |
$master_class[] = 'kc-raw-code'; | |
$apbd_industry_counter_box_markup = '<div class="apbd-industry-counter-box ' . esc_attr( implode( " ", $master_class ) ) . '">'; | |
if($icon_type == 1){ | |
$apbd_industry_counter_box_markup .= '<div class="apbd-industry-icon"> | |
<i class="' . esc_attr( $fa_icon ) .'"></i> | |
</div>'; | |
}else { | |
$counter_box_img_id = wp_get_attachment_image_src( $img_icon, 'thumbnail' ); | |
$apbd_industry_counter_box_markup .= '<div class="apbd-industry-img-icon"> | |
<img src="' . esc_url( $counter_box_img_id[0] ) .'" alt="' . esc_html( $sub_title ) .'" /> | |
</div>'; | |
} | |
if( !empty($sub_title) ){ | |
$apbd_industry_counter_box_markup .= '' . wpautop( esc_html( $sub_title ) ) . ''; | |
} | |
if( !empty($counter) ){ | |
$apbd_industry_counter_box_markup .= '<h2 class="counterup">' . esc_html( $counter ) .'</h2>'; | |
} | |
$apbd_industry_counter_box_markup .= '</div>'; | |
wp_enqueue_script('waypoints'); | |
wp_enqueue_script('counter-up'); | |
return $apbd_industry_counter_box_markup; | |
} | |
add_shortcode('apbd_industry_counter_box', 'apbd_industry_counter_box_shortcode'); | |
//service box 2 shortcode | |
function apbd_industry_service_box_shortcode2($atts){ | |
extract( shortcode_atts( array( | |
'img' => '', | |
'title' => '', | |
'description' => '', | |
'link' => '' | |
), $atts) ); | |
extract($atts); | |
// Create master class, return as an array | |
$master_class = apply_filters( 'kc-el-class', $atts ); | |
// Add new custom class to master class | |
$master_class[] = 'kc-raw-code'; | |
$apbd_industry_service_box_markup2 = '<div class="apbd-industry-service-box2 ' . esc_attr( implode( " ", $master_class ) ) . '">'; | |
$service_box2_img_id = wp_get_attachment_image_src( $img, 'large' ); | |
$apbd_industry_service_box_markup2 .= '<div class="apbd-industry-img-icon"> | |
<img src="' . esc_url( $service_box2_img_id[0] ) .'" alt="' . esc_html( $title ) .'" /> | |
</div>'; | |
if( !empty($title) ){ | |
$apbd_industry_service_box_markup2 .= '<h2>' . esc_html( $title ) .'</h2>'; | |
} | |
if( !empty($description) ){ | |
$apbd_industry_service_box_markup2 .= '' . wpautop( esc_html( $description ) ) . ''; | |
} | |
if( !empty($link) ){ | |
$link_array = explode('|', $link); | |
$apbd_industry_service_box_markup2 .= '<a class="industry-boxed-btn" href="'. $link_array[0] .'" target="'. $link_array[2] .'">'. $link_array[1] .'</a>'; | |
} | |
$apbd_industry_service_box_markup2 .= '</div>'; | |
return $apbd_industry_service_box_markup2; | |
} | |
add_shortcode('apbd_industry_service_box2', 'apbd_industry_service_box_shortcode2'); | |
//service box 2 shortcode | |
function apbd_industry_service_box_shortcode3($atts){ | |
extract( shortcode_atts( array( | |
'icon_type' => '1', | |
'fa_icon' => 'fa fa-star', | |
'img_icon' => '', | |
'title' => '', | |
'description' => '', | |
'link' => '' | |
), $atts) ); | |
extract($atts); | |
// Create master class, return as an array | |
$master_class = apply_filters( 'kc-el-class', $atts ); | |
// Add new custom class to master class | |
$master_class[] = 'kc-raw-code'; | |
$apbd_industry_service_box_markup3 = '<div class="apbd-industry-service-box3 ' . esc_attr( implode( " ", $master_class ) ) . '">'; | |
if($icon_type == 1){ | |
$apbd_industry_service_box_markup3 .= '<div class="apbd-industry-icon"> | |
<i class="' . esc_attr( $fa_icon ) .'"></i> | |
</div>'; | |
}else { | |
$service_box3_img_id = wp_get_attachment_image_src( $img_icon, 'thumbnail' ); | |
$apbd_industry_service_box_markup3 .= '<div class="apbd-industry-img-icon"> | |
<img src="' . esc_url( $service_box3_img_id[0] ) .'" alt="' . esc_html( $title ) .'" /> | |
</div>'; | |
} | |
if( !empty($title) ){ | |
$apbd_industry_service_box_markup3 .= '<h2>' . esc_html( $title ) .'</h2>'; | |
} | |
if( !empty($description) ){ | |
$apbd_industry_service_box_markup3 .= '' . wpautop( esc_html( $description ) ) . ''; | |
} | |
if( !empty($link) ){ | |
$link_array = explode('|', $link); | |
$apbd_industry_service_box_markup3 .= '<a class="inline-btn" href="'. $link_array[0] .'" target="'. $link_array[2] .'">'. $link_array[1] .'<i class="fa fa-caret-right"></i></a>'; | |
} | |
$apbd_industry_service_box_markup3 .= '</div>'; | |
return $apbd_industry_service_box_markup3; | |
} | |
add_shortcode('apbd_industry_service_box3', 'apbd_industry_service_box_shortcode3'); | |
//case study shortcode | |
function apbd_industry_case_study_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'img' => '', | |
'title' => '', | |
'description' => '', | |
'link' => '' | |
), $atts) ); | |
extract($atts); | |
// Create master class, return as an array | |
$master_class = apply_filters( 'kc-el-class', $atts ); | |
// Add new custom class to master class | |
$master_class[] = 'kc-raw-code'; | |
$apbd_industry_case_study_markup = '<div class="industry_case_study ' . esc_attr( implode( " ", $master_class ) ) . '">'; | |
$case_study_img_id = wp_get_attachment_image_src( $img, 'large' ); | |
$apbd_industry_case_study_markup .= '<div class="case-study-bg" style="background-image: url('.$case_study_img_id[0].');"></div>'; | |
if( !empty($title) ){ | |
$apbd_industry_case_study_markup .= '<h3>' . esc_html( $title ) .'</h3>'; | |
} | |
if( !empty($description) ){ | |
$apbd_industry_case_study_markup .= '' . wpautop( esc_html( $description ) ) . ''; | |
} | |
if( !empty($link) ){ | |
$link_array = explode('|', $link); | |
$apbd_industry_case_study_markup .= '<a class="case-study-readmore-btn" href="'. $link_array[0] .'" target="'. $link_array[2] .'">'. $link_array[1] .'</a>'; | |
} | |
$apbd_industry_case_study_markup .= '</div>'; | |
return $apbd_industry_case_study_markup; | |
} | |
add_shortcode('apbd_industry_case_study', 'apbd_industry_case_study_shortcode'); | |
// Post type for slider | |
function apbd_industry_slider_post_register() { | |
register_post_type( 'industry-slide', | |
array( | |
'labels' => array( | |
'name' => __( 'Slides' ), | |
'singular_name' => __( 'Slide' ) | |
), | |
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'), | |
'public' => false, | |
'show_ui' => true | |
) | |
); | |
} | |
add_action( 'init', 'apbd_industry_slider_post_register' ); | |
function apbd_industry_slider_taxonomy() { | |
register_taxonomy( | |
'slider_cat', | |
'industry-slide', | |
array( | |
'hierarchical' => true, | |
'label' => 'Slider Category', | |
'query_var' => true, | |
'show_admin_column' => true, | |
'rewrite' => array( | |
'slug' => 'slider-category', | |
'with_front' => true | |
) | |
) | |
); | |
} | |
add_action( 'init', 'apbd_industry_slider_taxonomy'); | |
function industry_theme_slide_cat_list(){ | |
$slider_categories = get_terms( 'slider_cat' ); | |
$slider_category_options = array( '', esc_html__( 'All Categories', 'textdomain') ); | |
if($slider_categories) { | |
foreach($slider_categories as $slider_category){ | |
$slider_category_options[$slider_category->term_id] = $slider_category->name; | |
} | |
} | |
return $slider_category_options; | |
} | |
//shrotcode for slider post type query | |
function apbd_slider_list_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'count' => 3, | |
'items' => 1, | |
'category' => '', | |
'loop' => true, | |
'dots' => true, | |
'nav' => true, | |
'autoplay' => true, | |
'autoplayTimeout' => 5000, | |
), $atts) ); | |
if( !empty($category) ){ | |
$args = array( | |
'posts_per_page' => $count, | |
'post_type' => 'industry-slide', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'slider_cat', | |
'field' => 'term_id', | |
'terms' => $category, | |
) | |
), | |
); | |
} else { | |
$args = array( | |
'posts_per_page' => $count, | |
'post_type' => 'industry-slide' | |
); | |
} | |
$query = new WP_Query( $args ); | |
$slide_random_number = rand(342345, 456547); | |
$apbd_slide_list = ' | |
<script> | |
jQuery(window).on( "load", function() { | |
jQuery("#industry-slides-'.$slide_random_number.'").owlCarousel({ | |
margin: 0, | |
items: '.$items.', | |
loop: '.$loop.', | |
dots: '.$dots.', | |
nav: '.$nav.', | |
navText: ["<i class=\'fa fa-angle-left\'></i>", "<i class=\'fa fa-angle-right\'></i>"], | |
autoplay: '.$autoplay.', | |
autoplayTimeout: '.$autoplayTimeout.' | |
}); | |
}); | |
</script> | |
<div id="industry-slides-'.$slide_random_number.'" class="owl-carousel industry-slides">'; | |
while($query->have_posts()) : $query->the_post(); | |
$post_id = get_the_ID(); | |
if(get_post_meta($post_id, '_apbd_industry_page_options', true)){ | |
$post_meta = get_post_meta($post_id, '_apbd_industry_page_options', true); | |
} else{ | |
$post_meta = array(); | |
} | |
if(array_key_exists('slider_text_color', $post_meta)) { | |
$slider_text_color = $post_meta['slider_text_color']; | |
} else{ | |
$slider_text_color = '#333'; | |
} | |
if(array_key_exists('slider_enable_overlay', $post_meta)) { | |
$slider_enable_overlay = $post_meta['slider_enable_overlay']; | |
} else{ | |
$slider_enable_overlay = false; | |
} | |
if(array_key_exists('slider_overlay_color', $post_meta)) { | |
$slider_overlay_color = $post_meta['slider_overlay_color']; | |
} else{ | |
$slider_overlay_color = false; | |
} | |
if(array_key_exists('slider_button_enable', $post_meta)) { | |
$slider_button_enable = $post_meta['slider_button_enable']; | |
} else{ | |
$slider_button_enable = false; | |
} | |
if(array_key_exists('slider_button_link', $post_meta)) { | |
$slider_button_link = $post_meta['slider_button_link']; | |
} else{ | |
$slider_button_link = ''; | |
} | |
if(array_key_exists('slider_button_bg_color', $post_meta)) { | |
$slider_button_bg_color = $post_meta['slider_button_bg_color']; | |
} else{ | |
$slider_button_bg_color = '#333'; | |
} | |
if(array_key_exists('slider_button_text', $post_meta)) { | |
$slider_button_text = $post_meta['slider_button_text']; | |
} else{ | |
$slider_button_text = 'Read More..'; | |
} | |
if(array_key_exists('slider_button_text_color', $post_meta)) { | |
$slider_button_text_color = $post_meta['slider_button_text_color']; | |
} else{ | |
$slider_button_text_color = '#fff'; | |
} | |
if(array_key_exists('slider_width', $post_meta)) { | |
$slider_width = $post_meta['slider_width']; | |
} else{ | |
$slider_width = 'col-md-6'; | |
} | |
if(array_key_exists('slider_offset', $post_meta)) { | |
$slider_offset = $post_meta['slider_offset']; | |
} else{ | |
$slider_offset = ''; | |
} | |
if(array_key_exists('slider_text_align', $post_meta)) { | |
$slider_text_align = $post_meta['slider_text_align']; | |
} else{ | |
$slider_text_align = 'left'; | |
} | |
$apbd_slide_list .= '<div style="background-image: url('. get_the_post_thumbnail_url( $post_id, 'full' ) .')" class="industry-single-slide">'; | |
if($slider_enable_overlay == true){ | |
$apbd_slide_list .= '<div style="background: '.$slider_overlay_color.'" class="industry-slide-overlay"></div>'; | |
} | |
$apbd_slide_list .= '<div class="industry-single-slide-inner"> | |
<div class="container"> | |
<div class="row"> | |
<div style="color: '.$slider_text_color.'" class="'. $slider_width .' '. $slider_offset .' text-'. $slider_text_align .'"> | |
<h2>'. get_the_title( $post_id ) . '</h2> | |
'. wpautop( get_the_content( $post_id ) ) .''; | |
if($slider_button_enable == true){ | |
$apbd_slide_list .= '<a style="color: '.$slider_button_text_color.'; background: '.$slider_button_bg_color.'" class="apbd-industry-slide-btn" href="'.$slider_button_link.'">'.$slider_button_text.'</a>'; | |
} | |
$apbd_slide_list .= '</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
'; | |
endwhile; | |
$apbd_slide_list .= '</div>'; | |
wp_reset_query(); | |
return $apbd_slide_list; | |
} | |
add_shortcode('apbd_industry_slider', 'apbd_slider_list_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment