Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Hotsugar Core
- * Plugin URI: http://www.themewaves.com/
- * Description: Themewaves Core Plugin
- * Version: 1.0.0
- * Author: Themewaves
- * Author URI: http://www.themewaves.com/
- * Text Domain: waves
- * License: GPL-2.0+
- * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
- * Domain Path: /languages
- *
- *
- * @package hotsugar-core
- * @author Themewaves
- * @license GPL-2.0+
- * @link themewaves.com
- * @copyright 2016 Themewaves
- */
- // If this file is called directly, abort.
- if ( ! defined( 'WPINC' ) ) {
- die;
- }
- define('HOTSUGAR_CORE_DIR', trailingslashit(plugin_dir_url( __FILE__ )));
- add_action('admin_init', 'hotsugar_elements_include');
- function hotsugar_elements_include(){
- require_once 'waves-shortcode.php';
- }
- add_action('init', 'hotsugar_core_init');
- function hotsugar_core_init(){
- add_shortcode( 'tw_posts','hotsugar_post_carousel' );
- add_shortcode( 'tw_btn', 'hotsugar_button' );
- }
- function hotsugar_post_carousel($atts){
- $atts = shortcode_atts( array(
- 'layout' => '',
- 'title' => '',
- 'cats' => '',
- 'posts_per_page' => '6',
- ), $atts, 'tw_carousel' );
- $class = !empty($atts['layout']) ? (' layout-'.$atts['layout']) : '';
- global $post, $hotsugar_options;
- $query = Array(
- 'post_type' => 'post',
- 'posts_per_page' => $atts['posts_per_page'],
- 'ignore_sticky_posts' => 1,
- );
- $cats = $atts['cats'];
- if (!empty($cats)) {
- $query['tax_query'] = Array(Array(
- 'taxonomy' => 'category',
- 'terms' => explode(',',$cats),
- 'field' => 'slug'
- )
- );
- }
- if(!empty($hotsugar_options['post__not_in'])){
- $query['post__not_in'] = $hotsugar_options['post__not_in'];
- }
- wp_enqueue_script('owl-carousel');
- $output = '<div class="tw-post-carousel">';
- $output .= !empty($atts['title']) ? ('<h3 class="tw-element-title">'.esc_html($atts['title']).'</h3>') : '';
- $output .= '<div class="owl-carousel'.esc_attr($class).'">';
- query_posts($query);
- if($atts['layout'] == '2'){
- while (have_posts()){the_post();
- $hotsugar_options['post__not_in'][]=$post->ID;
- $img = $data = '';
- if (has_post_thumbnail($post->ID)) {
- $img = hotsugar_image('hotsugar_carousel_2', true);
- if(hotsugar_metabox('parallax_post')){
- $img = hotsugar_image('hotsugar_carousel_3', true);
- wp_enqueue_script('jarallax');
- $data .= ' data-jarallax=\'{"speed": 0.4}\'';
- }
- if( !empty($img['url']) ){
- $data .= ' style=" background-image: url('.esc_url($img['url']).')"';
- }
- }
- $output .= '<div class="tw-owl-item">';
- $output .= '<div class="post-thumb tw-thumbnail" '. $data .'>';
- $cats = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "<span class='cat-item'>$2</span>", hotsugar_cats());
- $output .= '<div class="carousel-content"><div class="entry-cats">'.($cats).'</div>';
- $output .= '<h3 class="carousel-title">' . get_the_title() . '</h3>';
- $output .= '<div class="tw-meta"><span class="date">'.get_the_time(get_option('date_format')).'</span></div>';
- $output .= '</div>';
- if( !empty($img['url']) ){
- $output .= '<div class="image-overlay"></div>';
- }
- $output .= '</a></div>';
- $output .= "</div>";
- }
- }else{
- while (have_posts()){the_post();
- $hotsugar_options['post__not_in'][]=$post->ID;
- $img='';
- $format = get_post_format();
- if (has_post_thumbnail($post->ID)) {
- $img = '<a href="'.get_permalink().'">'.hotsugar_image('hotsugar_carousel_1').'</a>';
- if( $format == 'video' ){
- $img .= '<i class="video-format-icon ion-ios-play"></i>';
- }
- }
- $output .= '<div class="tw-owl-item">';
- $output .= '<div class="post-thumb tw-thumbnail">'.($img).'</div>';
- $output .= '<div class="carousel-content">';
- $output .= '<h3 class="carousel-title"><a href="'.esc_url(get_permalink()).'">' . get_the_title() . '</a></h3>';
- $output .= '<div class="tw-meta"><span class="date">'.get_the_time(get_option('date_format')).'</span></div>';
- $output .= '</div>';
- $output .= "</div>";
- }
- }
- wp_reset_query();
- $output .= '</div>';
- $output .= '</div>';
- return $output;
- }
- function hotsugar_button( $atts , $content ){
- $atts = shortcode_atts( array(
- 'link' => '',
- 'size' => 'medium',
- 'style' => 'flat',
- 'color' => '',
- 'round' => ''
- ), $atts, 'tw_button' );
- $class = $style = '';
- switch ($atts['size']) {
- case 'small':
- $class .= ' btn-s';
- break;
- case 'large':
- $class .= ' btn-l';
- break;
- }
- if($atts['style']=='border'){
- $class .= ' btn-border';
- $style .= 'style="color: '.esc_attr($atts['color']).'; border-color: '.esc_attr($atts['color']).';"';
- } else {
- $class .= ' btn-flat';
- $class .= $atts['color'] == '#fff' || $atts['color'] == '#ffffff' ? (' white-btn') : '';
- $style .= 'style="background-color: '.esc_attr($atts['color']).';border-color: '.esc_attr($atts['color']).';"';
- }
- if($atts['round']=='true'){
- $class .= ' btn-round';
- }
- $output = '<a href="'.esc_attr($atts['link']).'" class="btn'.esc_attr($class).'">'. $content .'</a>';
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement