/** * Render the shortcode * @param array $args Shortcode paramters * @param string $content Content between shortcode * @return string HTML output */ function render($args, $content = '') { global $smof_data; $defaults = FusionCore_Plugin::set_shortcode_defaults(array('class' => '', 'id' => '', 'blog_grid_column_spacing' => '40', 'blog_grid_columns' => '3', 'cat_slug' => '', 'excerpt' => 'yes', 'excerpt_length' => '', 'excerpt_words' => '50', 'exclude_cats' => '', 'layout' => 'large', 'meta_all' => 'yes', 'meta_author' => 'yes', 'meta_categories' => 'yes', 'meta_comments' => 'yes', 'meta_date' => 'yes', 'meta_link' => 'yes', 'meta_read' => 'yes', 'meta_tags' => 'no', 'number_posts' => '', 'order' => 'DESC', 'paging' => 'yes', 'scrolling' => 'infinite', 'strip_html' => 'yes', 'thumbnail' => 'yes', 'title' => 'yes', 'title_link' => 'yes', 'nopaging' => false, 'posts_per_page' => '-1', 'taxonomy' => 'category'), $args); extract($defaults); if (is_front_page() || is_home()) { $paged = get_query_var('paged') ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1); } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } $defaults['paged'] = $paged; // covert all attributes to correct values for WP query if ($defaults['number_posts']) { $defaults['posts_per_page'] = $defaults['number_posts']; } if ($defaults['posts_per_page'] == -1) { $defaults['nopaging'] = true; } $defaults['excerpt'] == "yes" ? $defaults['excerpt'] = true : ($defaults['excerpt'] = false); $defaults['meta_all'] == "yes" ? $defaults['meta_all'] = true : ($defaults['meta_all'] = false); $defaults['meta_author'] == "yes" ? $defaults['meta_author'] = true : ($defaults['meta_author'] = false); $defaults['meta_categories'] == "yes" ? $defaults['meta_categories'] = true : ($defaults['meta_categories'] = false); $defaults['meta_comments'] == "yes" ? $defaults['meta_comments'] = true : ($defaults['meta_comments'] = false); $defaults['meta_date'] == "yes" ? $defaults['meta_date'] = true : ($defaults['meta_date'] = false); $defaults['meta_link'] == "yes" ? $defaults['meta_link'] = true : ($defaults['meta_link'] = false); $defaults['meta_tags'] == "yes" ? $defaults['meta_tags'] = true : ($defaults['meta_tags'] = false); $defaults['paging'] == "yes" ? $defaults['paging'] = true : ($defaults['paging'] = false); $defaults['scrolling'] == "infinite" ? $defaults['paging'] = true : ($defaults['paging'] = $defaults['paging']); $defaults['strip_html'] == "yes" ? $defaults['strip_html'] = true : ($defaults['strip_html'] = false); $defaults['thumbnail'] == "yes" ? $defaults['thumbnail'] = true : ($defaults['thumbnail'] = false); $defaults['title'] == "yes" ? $defaults['title'] = true : ($defaults['title'] = false); $defaults['title_link'] == "yes" ? $defaults['title_link'] = true : ($defaults['title_link'] = false); if ($defaults['excerpt_length'] || $defaults['excerpt_length'] === '0') { $defaults['excerpt_words'] = $defaults['excerpt_length']; } //check for cats to exclude; needs to be checked via exclude_cats param and '-' prefixed cats on cats param //exclution via exclude_cats param $cats_to_exclude = explode(',', $defaults['exclude_cats']); $cats_id_to_exclude = array(); if ($cats_to_exclude) { foreach ($cats_to_exclude as $cat_to_exclude) { $id_obj = get_category_by_slug($cat_to_exclude); if ($id_obj) { $cats_id_to_exclude[] = $id_obj->term_id; } } if ($cats_id_to_exclude) { $defaults['category__not_in'] = $cats_id_to_exclude; } } //setting up cats to be used and exclution using '-' prefix on cats param; transform slugs to ids $cat_ids = ''; $categories = explode(',', $defaults['cat_slug']); if (isset($categories) && $categories) { foreach ($categories as $category) { $id_obj = get_category_by_slug($category); if ($id_obj) { if (strpos($category, '-') === 0) { $cat_ids .= '-' . $id_obj->cat_ID . ','; } else { $cat_ids .= $id_obj->cat_ID . ','; } } } } $defaults['cat'] = substr($cat_ids, 0, -1); if ($defaults['blog_grid_column_spacing'] === '0') { $defaults['blog_grid_column_spacing'] = '0.0'; } self::$args = $defaults; $fusion_query = new WP_Query($defaults); $this->query = $fusion_query; //prepare needed wrapping containers $html = ''; $html .= sprintf('<div %s>', FusionCore_Plugin::attributes('blog-shortcode')); if (self::$args['layout'] == 'grid' && self::$args['blog_grid_column_spacing']) { $html .= sprintf('<style type="text/css">.fusion-blog-shortcode-%s .grid-layout .post{padding:%spx;}</style>', $this->blog_sc_counter, $defaults['blog_grid_column_spacing'] / 2); } $html .= sprintf('<div %s>', FusionCore_Plugin::attributes('blog-shortcode-posts-container')); ob_start(); do_action('fusion_blog_shortcode_wrap_loop_open'); $wrap_loop_open = ob_get_contents(); ob_get_clean(); $html .= $wrap_loop_open; if (self::$args['layout'] == 'timeline') { $this->post_count = 1; $prev_post_timestamp = null; $prev_post_month = null; $prev_post_year = null; $first_timeline_loop = false; } //do the loop if ($fusion_query->have_posts()) { while ($fusion_query->have_posts()) { $fusion_query->the_post(); $this->post_id = get_the_ID(); if (self::$args['layout'] == 'timeline') { $post_timestamp = strtotime(get_the_date()); $this->post_month = date('n', $post_timestamp); $this->post_year = get_the_date('o'); $current_date = get_the_date('o-n'); $date_params['prev_post_month'] = $prev_post_month; $date_params['post_month'] = $this->post_month; $date_params['prev_post_year'] = $prev_post_year; $date_params['post_year'] = $this->post_year; ob_start(); do_action('fusion_blog_shortcode_timeline_date', $date_params); do_action('fusion_blog_shortcode_before_loop_timeline'); $before_loop_timeline_action = ob_get_contents(); ob_get_clean(); $html .= $before_loop_timeline_action; } else { ob_start(); do_action('fusion_blog_shortcode_before_loop'); $before_loop_action = ob_get_contents(); ob_get_clean(); $html .= $before_loop_action; } if (self::$args['layout'] == 'grid' || self::$args['layout'] == 'timeline') { $html .= sprintf('<div %s>', FusionCore_Plugin::attributes('post-wrapper')); } $this->header = array('title_link' => true); ob_start(); do_action('fusion_blog_shortcode_loop_header'); do_action('fusion_blog_shortcode_loop_content'); do_action('fusion_blog_shortcode_loop_footer'); do_action('fusion_blog_shortcode_after_loop'); $loop_actions = ob_get_contents(); ob_get_clean(); $html .= $loop_actions; if (self::$args['layout'] == 'grid' || self::$args['layout'] == 'timeline') { $html .= '</div>'; } if (self::$args['layout'] == 'timeline') { $prev_post_timestamp = $post_timestamp; $prev_post_month = $this->post_month; $prev_post_year = $this->post_year; $this->post_count++; } } } else { } ob_start(); do_action('fusion_blog_shortcode_wrap_loop_close'); $wrap_loop_close_action = ob_get_contents(); ob_get_clean(); $html .= $wrap_loop_close_action; $html .= '</div>'; if (self::$args['paging']) { ob_start(); themefusion_pagination($this->query->max_num_pages, $range = 2, $this->query); $pagination = ob_get_contents(); ob_get_clean(); $html .= $pagination; } $html .= '</div>'; $this->blog_sc_counter++; return $html; }
/** * Render the shortcode * @param array $args Shortcode paramters * @param string $content Content between shortcode * @return string HTML output */ function render($args, $content = '') { global $smof_data; $defaults = FusionCore_Plugin::set_shortcode_defaults(array('class' => '', 'id' => '', 'blog_grid_column_spacing' => '40', 'blog_grid_columns' => '3', 'cat_slug' => '', 'excerpt' => 'yes', 'excerpt_length' => '', 'excerpt_words' => '50', 'exclude_cats' => '', 'layout' => 'large', 'meta_all' => 'yes', 'meta_author' => 'yes', 'meta_categories' => 'yes', 'meta_comments' => 'yes', 'meta_date' => 'yes', 'meta_link' => 'yes', 'meta_read' => 'yes', 'meta_tags' => 'no', 'number_posts' => '6', 'offset' => '', 'order' => 'DESC', 'paging' => 'yes', 'scrolling' => 'infinite', 'strip_html' => 'yes', 'thumbnail' => 'yes', 'title' => 'yes', 'title_link' => 'yes', 'posts_per_page' => '-1', 'taxonomy' => 'category'), $args); extract($defaults); if (is_front_page() || is_home()) { $paged = get_query_var('paged') ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1); } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } $defaults['paged'] = $paged; // covert all attributes to correct values for WP query if ($defaults['number_posts']) { $defaults['posts_per_page'] = $defaults['number_posts']; } if ($defaults['posts_per_page'] == -1) { $defaults['paging'] = 'no'; } // Add hyphens for alternate layout options if ($defaults['layout'] == 'large alternate') { $defaults['layout'] = 'large-alternate'; } elseif ($defaults['layout'] == 'medium alternate') { $defaults['layout'] = 'medium-alternate'; } $defaults['load_more'] = FALSE; if ($defaults['scrolling'] != 'pagination') { $defaults['paging'] = TRUE; if ($defaults['scrolling'] == 'load_more_button') { $defaults['load_more'] = TRUE; } $defaults['scrolling'] = 'infinite'; } $defaults['meta_all'] == "yes" ? $defaults['meta_all'] = TRUE : ($defaults['meta_all'] = FALSE); $defaults['meta_author'] == "yes" ? $defaults['meta_author'] = TRUE : ($defaults['meta_author'] = FALSE); $defaults['meta_categories'] == "yes" ? $defaults['meta_categories'] = TRUE : ($defaults['meta_categories'] = FALSE); $defaults['meta_comments'] == "yes" ? $defaults['meta_comments'] = TRUE : ($defaults['meta_comments'] = FALSE); $defaults['meta_date'] == "yes" ? $defaults['meta_date'] = TRUE : ($defaults['meta_date'] = FALSE); $defaults['meta_link'] == "yes" ? $defaults['meta_link'] = TRUE : ($defaults['meta_link'] = FALSE); $defaults['meta_tags'] == "yes" ? $defaults['meta_tags'] = TRUE : ($defaults['meta_tags'] = FALSE); $defaults['paging'] == "yes" ? $defaults['paging'] = TRUE : ($defaults['paging'] = FALSE); $defaults['strip_html'] == "yes" ? $defaults['strip_html'] = TRUE : ($defaults['strip_html'] = FALSE); $defaults['thumbnail'] == "yes" ? $defaults['thumbnail'] = TRUE : ($defaults['thumbnail'] = FALSE); $defaults['title'] == "yes" ? $defaults['title'] = TRUE : ($defaults['title'] = FALSE); $defaults['title_link'] == "yes" ? $defaults['title_link'] = TRUE : ($defaults['title_link'] = FALSE); if ($defaults['excerpt_length'] || $defaults['excerpt_length'] === '0') { $defaults['excerpt_words'] = $defaults['excerpt_length']; } // Combine meta info into one variable $defaults['meta_info_combined'] = $defaults['meta_all'] * ($defaults['meta_author'] + $defaults['meta_date'] + $defaults['meta_categories'] + $defaults['meta_tags'] + $defaults['meta_comments'] + $defaults['meta_link']); // Create boolean that holds info whether content should be excerpted $defaults['is_zero_excerpt'] = $defaults['excerpt'] == 'yes' && $defaults['excerpt_words'] < 1 ? 1 : 0; //check for cats to exclude; needs to be checked via exclude_cats param and '-' prefixed cats on cats param //exclution via exclude_cats param $cats_to_exclude = explode(',', $defaults['exclude_cats']); $cats_id_to_exclude = array(); if ($cats_to_exclude) { foreach ($cats_to_exclude as $cat_to_exclude) { $id_obj = get_category_by_slug($cat_to_exclude); if ($id_obj) { $cats_id_to_exclude[] = $id_obj->term_id; } } if ($cats_id_to_exclude) { $defaults['category__not_in'] = $cats_id_to_exclude; } } //setting up cats to be used and exclution using '-' prefix on cats param; transform slugs to ids $cat_ids = ''; $categories = explode(',', $defaults['cat_slug']); if (isset($categories) && $categories) { foreach ($categories as $category) { $id_obj = get_category_by_slug($category); if ($id_obj) { if (strpos($category, '-') === 0) { $cat_ids .= '-' . $id_obj->cat_ID . ','; } else { $cat_ids .= $id_obj->cat_ID . ','; } } } } $defaults['cat'] = substr($cat_ids, 0, -1); if ($defaults['blog_grid_column_spacing'] === '0') { $defaults['blog_grid_column_spacing'] = '0.0'; } $defaults['blog_sc_query'] = TRUE; self::$args = $defaults; // Set the meta info settings for later use $this->meta_info_settings['post_meta'] = $defaults['meta_all']; $this->meta_info_settings['post_meta_author'] = !$defaults['meta_author']; $this->meta_info_settings['post_meta_date'] = !$defaults['meta_date']; $this->meta_info_settings['post_meta_cats'] = !$defaults['meta_categories']; $this->meta_info_settings['post_meta_tags'] = !$defaults['meta_tags']; $this->meta_info_settings['post_meta_comments'] = !$defaults['meta_comments']; $fusion_query = new WP_Query($defaults); $this->query = $fusion_query; //prepare needed wrapping containers $html = ''; $html .= sprintf('<div %s>', FusionCore_Plugin::attributes('blog-shortcode')); if (self::$args['layout'] == 'grid' && self::$args['blog_grid_column_spacing']) { $html .= sprintf('<style type="text/css">.fusion-blog-shortcode-%s .fusion-blog-layout-grid .fusion-post-grid{padding:%spx;}.fusion-blog-shortcode-%s .fusion-posts-container{margin-left: -%spx !important; margin-right:-%spx !important;}</style>', $this->blog_sc_counter, $defaults['blog_grid_column_spacing'] / 2, $this->blog_sc_counter, $defaults['blog_grid_column_spacing'] / 2, $defaults['blog_grid_column_spacing'] / 2); } $html .= sprintf('<div %s>', FusionCore_Plugin::attributes('blog-shortcode-posts-container')); ob_start(); do_action('fusion_blog_shortcode_wrap_loop_open'); $wrap_loop_open = ob_get_contents(); ob_get_clean(); $html .= $wrap_loop_open; // Initialize the time stamps for timeline month/year check if (self::$args['layout'] == 'timeline') { $this->post_count = 1; $prev_post_timestamp = null; $prev_post_month = null; $prev_post_year = null; $first_timeline_loop = false; } //do the loop if ($fusion_query->have_posts()) { while ($fusion_query->have_posts()) { $fusion_query->the_post(); $this->post_id = get_the_ID(); if (self::$args['layout'] == 'timeline') { // Set the time stamps for timeline month/year check $post_timestamp = get_the_time('U'); $this->post_month = date('n', $post_timestamp); $this->post_year = get_the_date('o'); $current_date = get_the_date('o-n'); $date_params['prev_post_month'] = $prev_post_month; $date_params['post_month'] = $this->post_month; $date_params['prev_post_year'] = $prev_post_year; $date_params['post_year'] = $this->post_year; // Set the timeline month label ob_start(); do_action('fusion_blog_shortcode_timeline_date', $date_params); $timeline_date = ob_get_contents(); ob_get_clean(); $html .= $timeline_date; } ob_start(); do_action('fusion_blog_shortcode_before_loop'); $before_loop_action = ob_get_contents(); ob_get_clean(); $html .= $before_loop_action; if (self::$args['layout'] == 'grid' || self::$args['layout'] == 'timeline') { $html .= sprintf('<div %s>', FusionCore_Plugin::attributes('fusion-post-wrapper')); } $this->header = array('title_link' => true); ob_start(); do_action('fusion_blog_shortcode_loop_header'); do_action('fusion_blog_shortcode_loop_content'); do_action('fusion_blog_shortcode_loop_footer'); do_action('fusion_blog_shortcode_after_loop'); $loop_actions = ob_get_contents(); ob_get_clean(); $html .= $loop_actions; if (self::$args['layout'] == 'timeline') { $prev_post_timestamp = $post_timestamp; $prev_post_month = $this->post_month; $prev_post_year = $this->post_year; $this->post_count++; } } } else { } ob_start(); do_action('fusion_blog_shortcode_wrap_loop_close'); $wrap_loop_close_action = ob_get_contents(); ob_get_clean(); $html .= $wrap_loop_close_action; $html .= '</div>'; if (self::$args['paging']) { ob_start(); fusion_pagination($this->query->max_num_pages, $range = 2, $this->query); $pagination = ob_get_contents(); ob_get_clean(); $html .= $pagination; } // If infinite scroll with "load more" button is used if (self::$args['load_more'] && self::$args['posts_per_page'] != -1) { $html .= sprintf('<div class="fusion-load-more-button fusion-clearfix">%s</div>', apply_filters('avada_load_more_pots_name', __('Load More Posts', 'fusion-core'))); } $html .= '</div>'; wp_reset_query(); $this->blog_sc_counter++; return $html; }