<?php /** * The Template for displaying all single posts. * * @package naked */ $post_categories = wp_get_post_categories(get_the_ID()); $post_categories = array_values($post_categories); $post_categories = thshpr_get_category_ids_string($post_categories); if (function_exists('fw_get_db_customizer_option')) { $sticky_header = fw_get_db_customizer_option('opt_header_sticky'); } if (function_exists('fw_get_db_post_option')) { //$value = fw_get_db_post_option( //'option_id/'. fw_get_db_post_option('option_id/'. 'gadget') $overrides = fw_get_db_post_option($post->ID, 'override_customizer'); $override_customizer = $overrides['option-type']; /** * These two ptions have to be in the post itself */ $subtitle = fw_get_db_post_option($post->ID, 'opt_subtitle'); $back_image = fw_get_db_post_option($post->ID, 'opt_parallax_image'); $background_image = $back_image['data']['icon']; if ($override_customizer == 'override') { /** * General Options */ $show_progress_indicator = $overrides['override']['opt_show_progress_indicator']; $sidebar_type = $overrides['override']['opt_sidebar_type']; $sticky_sidebar = $overrides['override']['opt_sticky_sidebar'];
/** * Front-end display of widget. * @since 0.1 */ function widget($args, $instance) { $post_categories = wp_get_post_categories(get_the_ID()); $post_categories = array_values($post_categories); $post_categories = thshpr_get_category_ids_string($post_categories); if (function_exists('fw_get_db_customizer_option')) { /** * Variables from customizer */ $widget_component_elements = fw_get_db_customizer_option('opt_widget_functionality'); $widget_category_tag_number = fw_get_db_customizer_option('opt_widget_number_categories'); $widget_divider_type = fw_get_db_customizer_option('opt_widget_divider_type'); $small_image_ratio = fw_get_db_customizer_option('opt_small_image_ratio'); $width = 390; $show_hover_effects = fw_get_db_customizer_option('opt_show_hover_effects'); $small_image_ratio = fw_get_db_customizer_option('opt_small_image_ratio'); $excerpt_length = fw_get_db_customizer_option('opt_widget_excerpt_length'); /** * Hover Items */ $opt_image_hover_item_top = fw_get_db_customizer_option('opt_image_hover_item_1'); $small_height = thshpr_generate_aspect_height($small_image_ratio, $width); if ($opt_image_hover_item_top['template'] == 0) { } else { if ($opt_image_hover_item_top['template'] == 1) { $hover_top = $opt_image_hover_item_top['1']['opt_image_hover_item_text']; } else { if ($opt_image_hover_item_top['template'] == 2) { $hover_top = '<i class="' . $opt_image_hover_item_top['2']['opt_image_hover_item_icon'] . '" data-value="' . $opt_image_hover_item_top['2']['opt_image_hover_item_1_icon'] . '"></i>'; } else { if ($opt_image_hover_item_top['template'] == 3) { $hover_top = '<img src="' . $opt_image_hover_item_top['3']['opt_image_hover_item_image']['url'] . '">'; } } } } $opt_image_hover_item_bottom = fw_get_db_customizer_option('opt_image_hover_item_2'); if ($opt_image_hover_item_bottom['template'] == 0) { } else { if ($opt_image_hover_item_bottom['template'] == 1) { $hover_bottom = $opt_image_hover_item_bottom['1']['opt_image_hover_item_text']; } else { if ($opt_image_hover_item_bottom['template'] == 2) { $hover_bottom = '<i class="' . $opt_image_hover_item_bottom['2']['opt_image_hover_item_icon'] . '" data-value="' . $opt_image_hover_item_bottom['2']['opt_image_hover_item_2_icon'] . '"></i>'; } else { if ($opt_image_hover_item_bottom['template'] == 3) { $hover_bottom = '<img src="' . $opt_image_hover_item_bottom['3']['opt_image_hover_item_image']['url'] . '">'; } } } } } else { /** * Variables when unyson plugin not added */ $widget_component_elements = array("Image", "Title", "Categories"); $widget_category_tag_number = 3; $small_image_ratio = fw_get_db_customizer_option('opt_small_image_ratio'); $width = 390; $show_hover_effects = fw_get_db_customizer_option('opt_show_hover_effects'); $small_image_ratio = 0.5625; $excerpt_length = 11; $show_hover_effects = "No"; $hover_top = '+'; $hover_bottom = 'N'; } $cache = wp_cache_get('theme_widget_related_posts', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Mini Blog', 'thshpr') : $instance['title'], $instance, $this->id_base); if (!($number = (int) $instance['number'])) { $number = 10; } else { if ($number < 1) { $number = 1; } else { if ($number > 15) { $number = 15; } } } global $post; $tags = wp_get_post_tags($post->ID); $tagIDs = array(); if ($tags) { $tagcount = count($tags); for ($i = 0; $i < $tagcount; $i++) { $tagIDs[$i] = $tags[$i]->term_id; } $query = array('tag__in' => $tagIDs, 'post__not_in' => array($post->ID), 'showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1); /** * Get category ID's */ $catids = array(); foreach ($instance['cat'] as $name) { $term = get_term_by("name", $name, 'category'); $catids[] = $term->term_id; //store the id of each slug in $catids } $post_category = implode(',', $catids); if (!empty($instance['cat'])) { $query['cat'] = $post_category; } $the_query = new WP_Query($query); if ($the_query->have_posts()) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<div class="related-posts-wrap posts posts-widget">'; echo '<ul class="thumb-list">'; while ($the_query->have_posts()) { echo '<li>'; $the_query->the_post(); $item_string = ""; //set it up for concat $post_format = get_post_format(); include locate_template('widget-templates/components-string.php'); //generates title string from customzed options echo $item_string; echo '</li>'; } echo '</ul>'; echo '</div>'; echo $after_widget; // Reset the global $the_post as this query will have roflstomped on it wp_reset_query(); } $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('theme_widget_related_posts', $cache, 'widget'); } }