Skip to content

Instantly share code, notes, and snippets.

@mmh4560
Last active September 4, 2017 04:50
Show Gist options
  • Save mmh4560/940dcab0001688df6a7aede5a281cf7a to your computer and use it in GitHub Desktop.
Save mmh4560/940dcab0001688df6a7aede5a281cf7a to your computer and use it in GitHub Desktop.
metabox, shortcode
<?php // Slider Shortcode
function inds_owl_slider() {
register_post_type( 'inds-slider', array(
'labels' => array(
'name' => 'Sliders',
'add_new' => 'Add New Slider',
'add_new_item' => 'Add New Slider',
'edit_item' => 'Edit Slider',
),
'public' => false,
'show_ui' => true,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
));
}
add_action('init', 'inds_owl_slider');
// Slider Shortcode
function custom_post_plugin_stcd($attr, $content = null) {
extract( shortcode_atts( array(
'count' => 2,
'type' => 'inds-slider'
), $attr));
$args = array(
'post_type' => $type,
'posts_per_page' => $count
);
$get_post = new WP_Query($args);
$slider_random_number = rand(23456789, 96378543);
$indst_tm_slider_markup = '
<script>
jQuery(window).load(function() {
jQuery("#inds-slides-'.$slider_random_number.'").owlCarousel({
items : 1,
loop : true,
dots : true,
nav : true,
navText : ["<i class=\'fa fa-angle-left\'></i>", "<i class=\'fa fa-angle-right\'></i>"],
autoplay : false
});
});
</script>
<div id="inds-slides-'.$slider_random_number.'" class="owl-carousel inds-tm-slider">';
while($get_post->have_posts()) : $get_post->the_post();
$post_id = get_the_ID();
if(get_post_meta( $post_id, 'indst_tm_slide_meta', true)) {
$slide_meta = get_post_meta( $post_id, 'indst_tm_slide_meta', true);
} else{
$slide_meta = array();
}
if(array_key_exists('text_color', $slide_meta)) {
$text_color = $slide_meta['text_color'];
}else {
$text_color = '#333333';
}
if(array_key_exists('enable_overly', $slide_meta)) {
$enable_overly = $slide_meta['enable_overly'];
}else {
$enable_overly = false;
}
if(array_key_exists('overly_opacity', $slide_meta)) {
$overly_opacity = $slide_meta['overly_opacity'];
}else {
$overly_opacity = '80';
}
if(array_key_exists('overly_color', $slide_meta)) {
$overly_color = $slide_meta['overly_color'];
}else {
$overly_color = '#333333';
}
$indst_tm_slider_markup .= '
<div style="background-image:url('.get_the_post_thumbnail_url($post_id, 'large').')" class="inst-slingle-slide">';
if($enable_overly == true) {
$indst_tm_slider_markup .= '<div style="opacity:.'.$overly_opacity.';background-color:'.$overly_color.'" class="indst-slide-overlay"></div>';
}
$indst_tm_slider_markup .= '
<div class="inst-single-inner">
<div class="container">
<div class="row">
<div style="color:'.$text_color.'" class="col-md-6">
<h2>'.get_the_title($post_id).'</h2>
'.wpautop(get_the_content($post_id)).'
</div>
</div>
</div>
</div>
</div>
';
endwhile;
$indst_tm_slider_markup .= '</div>';
wp_reset_query();
return $indst_tm_slider_markup;
}
add_shortcode('indst_tm_sld_shortcode', 'custom_post_plugin_stcd');
<a href="http://designmusarrof.com/rrf/slider-page/">Live work here</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment