/** * Render the widget. * * @param array $args General widget arguments. * @param array $instance Specific instance arguments. * @uses WebcomicTag::webcomic_list_terms() * @uses WebcomicTag::webcomic_term_cloud() * @uses WebcomicTag::webcomic_dropdown_terms() * @uses WebcomicTag::get_webcomic_collection() */ public function widget($args, $instance) { extract($args); extract($instance); $a = array_merge($args, $instance); $object = get_queried_object(); unset($a['name']); $a['target'] = empty($a['target']) ? 'archive' : $a['target']; $a['taxonomy'] = $collection ? "{$collection}_character" : WebcomicTag::get_webcomic_collection() . '_character'; $a['show_option_none'] = __('Select Character', 'webcomic'); if (!empty($object->taxonomy) and $a['taxonomy'] === $object->taxonomy) { $a['selected'] = $object->term_id; } if ('list' === $format) { $output = WebcomicTag::webcomic_list_terms($a); } elseif ('dropdown' === $format) { $output = WebcomicTag::webcomic_dropdown_terms($a); } else { $output = WebcomicTag::webcomic_term_cloud($a); } if ($output) { echo $before_widget, empty($title) ? '' : $before_title . $title . $after_title, $output, $after_widget; } }
/** * Render a `<select>` element for webcomic characters. * * ### Arguments * * - `string` **$select_name** - Value for the name attribute of the `<select>` element. * - `string` **$id** - Value of the id attribute of the `<select>` element. * - `mixed` **$class** - String or array of additional classes for the `<select>` element. * - `string` **$show_option_all** - String to display for an "all" `<option>` (value="0"). * - `string` **$show_option_none** - String to display for a "none" `<option>` (value="-1"). * - `boolean` **$hide_if_empty** - Whether to display the `<select>` even if it contains no `<option>'s`. * - `string` **$collection** - The collection characters must belong to. * - `string` **$orderby** - What field to sort characters by. Defaults to 'name'. * - `object` **$walker** - Custom walker object. Defaults Walker_WebcomicTerm_Dropdown. * - `integer` **$depth** - How deep the walker should run. Defaults to 0 (all levels). A -1 depth will result in flat output. * - `boolean` **$webcomics** - Whether to display a dropdown of webcomic posts grouped by character. The 'hide_empty' argument is ignored when $webcomics is true. * - `boolean` **$show_count** - Whether to display the total number of webcomics featuring a character. * - `string` **$target** - The target url for characters, one of 'archive', 'first', 'last', or 'random'. Defaults to 'archive'. * - `integer` **$selected** - The ID of the selected character or webcomic. * * <code class="php"> * // render a dropdown of characters featured in at least one webcomic of the current collection * webcomic_dropdown_characters(); * * // render a dropdown of all characters in collection 42 linked to the beginning of each character with a default option * webcomic_dropdown_characters( array( 'collection' => 'webcomic42', 'hide_empty' => false, 'target' => 'first', 'show_option_all' => '- Characters -' ) ); * * // render a dropdown of published webcomics grouped by character in collection 42 * webcomic_dropdown_characters( array( 'collection' => 'webcomic42', 'show_option_all' => '- Comics by Character -', 'webcomics' => true ) ); * </code> * * <code class="bbcode"> * // render a dropdown of characters featured in at least one webcomic of the current collection * [webcomic_dropdown_characters] * * // render a dropdown of all characters in collection 42 linked to the beginning of each character with a default option * [webcomic_dropdown_characters collection="webcomic42" hide_empty="false" target="first" show_option_all="- Characters -"] * * // render a dropdown of published webcomics grouped by character in collection 42 * [webcomic_dropdown_characters collection="webcomic42" show_option_all="- Comics by Character -" webcomics="true"] * </code> * * @package Webcomic * @param array $args Array of arguments. See the WebcomicTag::webcomic_dropdown_terms() function description for detailed information. * @uses WebcomicTag::get_webcomic_collection() * @uses WebcomicTag::webcomic_dropdown_terms() */ function webcomic_dropdown_characters($args = array()) { $r = wp_parse_args($args, array('select_name' => 'webcomic_terms', 'id' => '', 'class' => '', 'show_option_all' => '', 'show_option_none' => '', 'hierarchical' => true, 'hide_if_empty' => true, 'collection' => '', 'orderby' => 'name', 'walker' => false, 'depth' => 0, 'webcomics' => false, 'show_count' => false, 'target' => 'archive', 'selected' => 0)); $collection = $r['collection'] ? $r['collection'] : WebcomicTag::get_webcomic_collection(); if (taxonomy_exists("{$collection}_character")) { $r['taxonomy'] = "{$collection}_character"; echo WebcomicTag::webcomic_dropdown_terms($r); } }
/** * Handle webcomic_dropdown_terms shortcodes. * * @param array $atts Shortcode attributes. * @param string $content Shortcode content. * @param string $name Shortcode name. * @return string * @uses WebcomicTag::get_webcomic_collection() * @uses WebcomicTag::webcomic_dropdown_terms() */ public function webcomic_dropdown_terms($atts, $content, $name) { $r = shortcode_atts(array('select_name' => 'webcomic_terms', 'id' => '', 'class' => '', 'show_option_all' => '', 'show_option_none' => '', 'hierarchical' => true, 'hide_if_empty' => true, 'collection' => '', 'order_by' => 'term_group', 'walker' => false, 'depth' => 0, 'webcomics' => false, 'show_count' => false, 'target' => 'archive', 'selected' => 0), $atts); $collection = $r['collection'] ? $r['collection'] : WebcomicTag::get_webcomic_collection(); if (false !== strpos($name, 'storyline')) { $tax = 'storyline'; } elseif (false !== strpos($name, 'character')) { $tax = 'character'; } else { $tax = ''; } if (taxonomy_exists("{$collection}_{$tax}")) { $r['taxonomy'] = "{$collection}_{$tax}"; return WebcomicTag::webcomic_dropdown_terms($r); } }