Skip to content

Instantly share code, notes, and snippets.

@kamalinfo
Last active November 25, 2017 18:22
Show Gist options
  • Save kamalinfo/d36e883ba0ff244ff323ba9a4a9119ab to your computer and use it in GitHub Desktop.
Save kamalinfo/d36e883ba0ff244ff323ba9a4a9119ab to your computer and use it in GitHub Desktop.
<?php
/**
* =======================================================
* KC Shortcode Map
* =======================================================
*/
add_action('init', 'themename_recent_posttype'); // Call kc_add_map function ///
if(!function_exists('themename_recent_posttype')):
function themename_recent_posttype(){
if(function_exists('kc_add_map')): // if kingComposer is active
kc_add_map(
array(
'themename_post' => array( // <-- shortcode tag name
'name' => esc_html__('Recent Post', 'themename'),
'description' => esc_html__('Description Here', 'themename'),
'icon' => 'fa-header',
'category' => themename_SHORTCODE_CATEGORY,
'params' => array(
// .............................................
// ..... // Content TAB
// .............................................
'General' => array(
array(
'type' => 'select',
'label' => esc_html__( 'Blog Style', 'themename' ),
'name' => 'blog_style',
'description' => esc_html__( 'Blog style ', 'themename' ),
'options' => array(
'1' => esc_html__( 'Blog style 1', 'themename' ),
'2' => esc_html__( 'Blog style 2', 'themename' ),
)
),
array(
'type' => 'number_slider',
'label' => esc_html__( 'Number Of Post', 'themename' ),
'name' => 'number',
'description' => esc_html__( 'Number Of post', 'themename' ),
'value' => '3',
),
array(
'type' => 'number_slider',
'label' => esc_html__( 'Number Of Words', 'themename' ),
'name' => 'word_count',
'description' => esc_html__( 'Number Of Words', 'themename' ),
'value' => '30',
),
array(
'type' => 'select',
'label' => esc_html__( 'Number Of Column', 'themename' ),
'name' => 'columns',
'description' => esc_html__( 'Number Of Column', 'themename' ),
'options' => array(
'1' => esc_html__('One Column','themename'),
'2' => esc_html__('Two Column','themename'),
'3' => esc_html__('Three Column','themename'),
'4' => esc_html__('Four Column','themename'),
)
),
array(
'type' => 'toggle',
'label' => esc_html__( 'Share Link show Hide', 'themename' ),
'name' => 'share_link',
'value' => 'yes',
'description' => esc_html__( 'Control share comment link area control', 'themename' ),
),
array(
'name' => 'custom_css_class',
'label' => esc_html__('CSS Class','themename'),
'description' => esc_html__('Custom css class for css customisation','themename'),
'type' => 'text'
),
), // content
// .............................................
// ..... // Styling
// .............................................
'styling' => array(
array(
'name' => 'custom_css',
'type' => 'css',
'options' => array(
array(
'screens' => 'any,1024,999,767,479',
'Title' => array(
array(
'property' => 'color',
'label' => esc_html__( 'Title Color', 'themename' ),
'selector' => '+ .blog-info h4 a'
),
array(
'property' => 'color',
'label' => esc_html__( 'Hover Color', 'themename' ),
'selector' => '+ .blog-info h4 a:hover'
),
array(
'property' => 'font-family',
'label' => esc_html__( 'Title Font Family', 'themename' ),
'selector' => '+ .blog-info h4 a'
),
array(
'property' => 'font-size',
'label' => esc_html__( 'Title Font Size', 'themename' ),
'selector' => '+ .blog-info h4 a'
),
array(
'property' => 'font-weight',
'label' => esc_html__( 'Title Font Weight','themename' ),
'selector' => '+ .blog-info h4 a'
),
array(
'property' => 'text-transform',
'label' => esc_html__( 'Title Text Transform', 'themename' ),
'selector' => '+ .blog-info h4 a'
),
),
///////
'Description' => array(
array(
'property' => 'color',
'label' => esc_html__( ' Color', 'themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'font-family',
'label' => esc_html__( ' Font Family', 'themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'font-size',
'label' => esc_html__( ' Font Size', 'themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'font-weight',
'label' => esc_html__( ' Font Weight','themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'line-height',
'label' => esc_html__( 'Line Height','themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'text-transform',
'label' => esc_html__( ' Text Transform', 'themename' ),
'selector' => '+ .blog-info > p'
),
),
///////
'Post Info' => array(
array(
'property' => 'color',
'label' => esc_html__( ' Color', 'themename' ),
'selector' => '+ .like-share a,.like-share > span i,.like-share > span'
),
array(
'property' => 'font-family',
'label' => esc_html__( ' Font Family', 'themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'font-size',
'label' => esc_html__( ' Font Size', 'themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'font-weight',
'label' => esc_html__( ' Font Weight','themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'line-height',
'label' => esc_html__( 'Line Height','themename' ),
'selector' => '+ .blog-info > p'
),
array(
'property' => 'text-transform',
'label' => esc_html__( ' Text Transform', 'themename' ),
'selector' => '+ .blog-info > p'
),
),
///
'Read More' => array(
array(
'property' => 'color',
'label' => esc_html__( ' Color', 'themename' ),
'selector' => '+ .text-dark-red'
),
array(
'property' => 'color',
'label' => esc_html__( 'Hover Color', 'themename' ),
'selector' => '+ .text-dark-red:hover'
),
array(
'property' => 'font-family',
'label' => esc_html__( ' Font Family', 'themename' ),
'selector' => '+ .text-dark-red'
),
array(
'property' => 'font-size',
'label' => esc_html__( ' Font Size', 'themename' ),
'selector' => '+ .text-dark-red'
),
array(
'property' => 'font-weight',
'label' => esc_html__( ' Font Weight','themename' ),
'selector' => '+ .text-dark-red a'
),
array(
'property' => 'text-transform',
'label' => esc_html__( ' Text Transform', 'themename' ),
'selector' => '+ .text-dark-red a'
),
),
///
'Box' => array(
array(
'property' => 'padding',
'label' => esc_html__( ' Padding','themename' ),
'selector' => '+.blog-area',
),
),
)
) //End of options
)
), //End of styling
'animate' => array(
array(
'name' => 'animate',
'type' => 'animate'
)
), //End of animate
// .............................................
// .............................................
// .............................................
/////////////////////////////////////////////////////////
)// Params
)// end shortcode key
)// first array
); // End add map
endif;
}
endif;
/*
* =======================================================
* Register Shortcode
* =======================================================
*/
//[themename_feature icon="" image="" title="" count="" custom_css_class=""]
if(!function_exists('themename_post_shortcode')){
function themename_post_shortcode($atts,$content){
ob_start();
extract( $atts );
//custom class
$wrap_class = apply_filters( 'kc-el-class', $atts );
if( !empty( $custom_class ) ):
$wrap_class[] = $custom_class;
endif;
$extra_class = implode( ' ', $wrap_class );
?>
<div class="blog-area post-single <?php if( $blog_style == '2' ){ echo 'blog-2'; } ?> <?php echo esc_attr( $extra_class ); ?> <?php echo esc_attr( $custom_css_class ); ?>">
<?php
$args = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => $number,
));
while($args->have_posts()):$args->the_post();
$colwidth = 'col-lg-4 col-md-4 col-sm-6 col-xs-12';
if($columns != ''){
$column = round(12/$columns);
$colwidth = 'col-md-'.$column.' col-sm-6 col-xs-12';
}
?>
<div class="<?php echo esc_attr($colwidth); ?>">
<div class="single-blog">
<?php if( $blog_style == '2' ){ ?>
<div class="blog-photo">
<?php if( has_post_thumbnail()): ?>
<a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php the_post_thumbnail('themename_blog_three'); ?></a>
<?php endif; ?>
<div class="like-share text-center fix">
<?php echo themename_get_post_like_link( get_the_ID() ); ?>
<span>
<i class="zmdi zmdi-comments"></i>
<?php comments_popup_link(esc_html__('0','themename'),esc_html__('1','themename'),' ',esc_html__('Comment off','themename') ); ?>
</span>
<?php laest_post_share(); ?>
</div>
</div>
<div class="blog-info">
<div class="post-meta fix">
<div class="post-year floatleft">
<h4 class="post-title"><a href="<?php echo esc_url( get_the_permalink() ); ?>" tabindex="0"><?php the_title(); ?></a></h4>
</div>
</div>
<p><?php echo wp_trim_words( get_the_content(), $word_count ); ?></p>
<a href="<?php echo esc_url( get_the_permalink() ); ?>" class="button-2 text-dark-red"><?php themename_read_more(); ?></a>
</div>
<?php }else{ ?>
<?php if( has_post_thumbnail() ): ?>
<div class="blog-photo">
<a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php the_post_thumbnail('themename_blog_three'); ?></a>
</div>
<?php endif; ?>
<div class="blog-info">
<div class="post-meta fix">
<div class="post-year floatleft">
<h4 class="post-title"><a href="<?php echo esc_url( get_the_permalink() ); ?>" tabindex="0"><?php the_title(); ?></a></h4>
</div>
</div>
<?php if($share_link=='yes'): ?>
<div class="like-share fix">
<?php echo themename_get_post_like_link( get_the_ID() ); ?>
<span>
<i class="zmdi zmdi-comments"></i>
<?php comments_popup_link(esc_html__('0','themename'),esc_html__('1','themename'),' ',esc_html__('Comment off','themename') ); ?>
</span>
<?php laest_post_share(); ?>
</div>
<?php endif; ?>
<p><?php echo wp_trim_words( get_the_content(), $word_count ); ?></p>
<a href="<?php echo esc_url( get_the_permalink() ); ?>" class="button-2 text-dark-red"><?php themename_read_more(); ?></a>
</div>
<?php } ?>
</div>
</div>
<?php endwhile;
wp_reset_postdata();
?>
</div>
<?php
return ob_get_clean();
}
add_shortcode('themename_post' ,'themename_post_shortcode');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment