/** * Default widget front end display method. * * @since 1.0.0 * * @param array $args Args specific to the widget area (sidebar). * @param array $instance Widget instance settings. */ function widget($args, $instance) { extract($args); $instance['title_raw'] = $instance['title']; $instance['title'] = apply_filters('widget_title', empty($instance['title']) ? get_the_title($instance['post_id']) : $instance['title'], $instance, $this->id_base); $instance['title'] = apply_filters('audiotheme_widget_title', $instance['title'], $instance, $args, $this->id_base); echo $before_widget; // Output filter is for backwards compatibility. if ($output = apply_filters('audiotheme_widget_video_output', '', $instance, $args)) { echo empty($instance['title']) ? '' : $before_title . $instance['title'] . $after_title; echo $output; } else { $post = get_post($instance['post_id']); $image_size = apply_filters('audiotheme_widget_video_image_size', 'thumbnail', $instance, $args); $image_size = apply_filters('audiotheme_widget_video_image_size-' . $args['id'], $image_size, $instance, $args); $data = array(); $data['args'] = $args; $data['after_title'] = $args['after_title']; $data['before_title'] = $args['before_title']; $data['image_size'] = $image_size; $data['post'] = get_post($instance['post_id']); $data = array_merge($instance, $data); $template = audiotheme_locate_template(array("widgets/{$args['id']}_video.php", 'widgets/video.php')); audiotheme_load_template($template, $data); } echo $after_widget; }
/** * Load a template file. * * @since 1.5.0 * * @param string|array $template_file Absolute path to a file or list of template parts. * @param array $data Optional. List of variables to extract into the template scope. * @param bool $locate Optional. Whether the $template_file argument should be located. Default false. * @param bool $require_once Optional. Whether to require_once or require. Default false. */ function audiotheme_load_template($template_file, $data = array(), $locate = false, $require_once = false) { if (is_array($data) && !empty($data)) { extract($data, EXTR_SKIP); unset($data); } // Locate the template file specified as the first parameter. if ($locate) { $template_file = audiotheme_locate_template($template_file); } if ($require_once) { require_once $template_file; } else { require $template_file; } }
/** * Default widget front end display method. * * @since 1.0.0 * * @param array $args Args specific to the widget area (sidebar). * @param array $instance Widget instance settings. */ function widget($args, $instance) { $cache = (array) wp_cache_get('audiotheme_widget_upcoming_gigs', 'widget'); if (isset($cache[$this->id])) { echo $cache[$this->id]; return; } extract($args); $instance['title_raw'] = empty($instance['title']) ? '' : $instance['title']; $instance['title'] = apply_filters('widget_title', empty($instance['title']) ? __('Upcoming Gigs', 'audiotheme') : $instance['title'], $instance, $this->id_base); $instance['title'] = apply_filters('audiotheme_widget_title', $instance['title'], $instance, $args, $this->id_base); $instance['date_format'] = apply_filters('audiotheme_widget_upcoming_gigs_date_format', get_option('date_format')); $instance['number'] = empty($instance['number']) || !absint($instance['number']) ? 5 : absint($instance['number']); $loop = new Audiotheme_Gig_Query(apply_filters('audiotheme_widget_upcoming_gigs_loop_args', array('no_found_rows' => true, 'posts_per_page' => $instance['number']))); // Add a class with the number of gigs to display. $output = preg_replace('/class="([^"]+)"/', 'class="$1 widget-items-' . $instance['number'] . '"', $before_widget); if ($inside = apply_filters('audiotheme_widget_upcoming_gigs_output', '', $instance, $args, $loop)) { // Call loop have_posts() for backwards compatibility with themes // that don't call it in their filters. $loop->have_posts(); $output .= empty($instance['title']) ? '' : $before_title . $instance['title'] . $after_title; $output .= $inside; } else { $data = array(); $data['args'] = $args; $data['after_title'] = $args['after_title']; $data['before_title'] = $args['before_title']; $data['loop'] = $loop; $data = array_merge($instance, $data); ob_start(); $template = audiotheme_locate_template(array("widgets/{$args['id']}_upcoming-gigs.php", 'widgets/upcoming-gigs.php')); audiotheme_load_template($template, $data); $output .= ob_get_clean(); } wp_reset_postdata(); $output .= $after_widget; echo $output; $cache[$this->id] = $output; wp_cache_set('audiotheme_widget_upcoming_gigs', $cache, 'widget'); }
/** * Load video templates. * * Templates should be included in an /audiotheme/ directory within the theme. * * @since 1.0.0 * * @param string $template Template path. * @return string */ function audiotheme_video_template_include($template) { if (is_post_type_archive('audiotheme_video') || is_tax('audiotheme_video_category')) { if (is_tax()) { $term = get_queried_object(); $taxonomy = str_replace('audiotheme_', '', $term->taxonomy); $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php"; $templates[] = "taxonomy-{$taxonomy}.php"; } $templates[] = 'archive-video.php'; $template = audiotheme_locate_template($templates); do_action('audiotheme_template_include', $template); } elseif (is_singular('audiotheme_video')) { $template = audiotheme_locate_template('single-video.php'); do_action('audiotheme_template_include', $template); } return $template; }
/** * Helper method to generate widget output. * * @since 1.0.0 * * @param array $args Args specific to the widget area (sidebar). * @param array $instance Widget instance settings. */ function render($args, $instance) { $output = $args['before_widget']; // Allow the output to be filtered. if ($inside = apply_filters('audiotheme_widget_recent_posts_output', '', $instance, $args)) { $output .= $inside; } else { $data = array(); $data['args'] = $args; $data['after_title'] = $args['after_title']; $data['before_title'] = $args['before_title']; $data['feed_link'] = 'post' === $instance['post_type'] ? get_bloginfo('rss2_url') : get_post_type_archive_feed_link($instance['post_type']); $data['instance'] = $instance; $data['loop'] = new WP_Query($instance['loop_args']); $data['show_date'] = !empty($instance['show_date']); $data['show_excerpts'] = !empty($instance['show_excerpts']); $data['show_feed_link'] = !empty($instance['show_feed_link']) && !empty($data['feed_link']); $data['title'] = empty($instance['title']) ? '' : $instance['title']; $data = array_merge($instance, $data); ob_start(); $template = audiotheme_locate_template(array("widgets/{$args['id']}_recent-posts.php", 'widgets/recent-posts.php')); audiotheme_load_template($template, $data); $output .= ob_get_clean(); wp_reset_postdata(); } $output .= $args['after_widget']; return $output; }
/** * Load discography templates. * * Templates should be included in an /audiotheme/ directory within the theme. * * @since 1.0.0 * * @param string $template Template path. * @return string */ function audiotheme_discography_template_include($template) { if (is_post_type_archive(array('audiotheme_record', 'audiotheme_track')) || is_tax('audiotheme_record_type')) { if (is_post_type_archive('audiotheme_track')) { $templates[] = 'archive-track.php'; } if (is_tax()) { $term = get_queried_object(); $slug = str_replace('record-type-', '', $term->slug); $taxonomy = str_replace('audiotheme_', '', $term->taxonomy); $templates[] = "taxonomy-{$taxonomy}-{$slug}.php"; $templates[] = "taxonomy-{$taxonomy}.php"; } $templates[] = 'archive-record.php'; $template = audiotheme_locate_template($templates); do_action('audiotheme_template_include', $template); } elseif (is_singular('audiotheme_record')) { $template = audiotheme_locate_template('single-record.php'); do_action('audiotheme_template_include', $template); } elseif (is_singular('audiotheme_track')) { $template = audiotheme_locate_template('single-track.php'); do_action('audiotheme_template_include', $template); } return $template; }
/** * Load gig templates. * * Templates should be included in an /audiotheme/ directory within the theme. * * @since 1.0.0 * * @param string $template Template path. * @return string */ function audiotheme_gig_template_include($template) { if (is_post_type_archive('audiotheme_gig')) { $template = audiotheme_locate_template('archive-gig.php'); do_action('audiotheme_template_include', $template); } elseif (is_singular('audiotheme_gig')) { $template = audiotheme_locate_template('single-gig.php'); do_action('audiotheme_template_include', $template); } return $template; }