Ejemplo n.º 1
0
 /** Widget front-end */
 public function widget($args, $instance)
 {
     extract($args);
     // Set defaults
     $defaults = array('container' => 'list', 'category' => "all", 'show_cat_title' => true);
     $instance = wp_parse_args($instance, $defaults);
     $title = apply_filters('widget_title', $instance['title']);
     $args['container'] = $instance['container'];
     $args['category'] = $instance['category'];
     $args['show_cat_title'] = $instance['show_cat_title'];
     $lnbrk = "\n";
     switch ($args['container']) {
         case 'paragraph':
             $container = array('show_cat_title' => $args['show_cat_title'], 'container_header' => 'h3', 'container_start' => '<div class="wd-faq wd-faq-div">', 'container_stop' => '</div>', 'item_start' => '<p>', 'item_stop' => '</p>', 'question_start' => '<strong>', 'question_stop' => '</strong>', 'answer_start' => '', 'answer_stop' => '');
             break;
         case 'accordion':
             $container = array('show_cat_title' => $args['show_cat_title'], 'container_header' => 'h3', 'container_start' => '<div class="wd-faq wd-faq-accordion">', 'container_stop' => '</div>', 'item_start' => '', 'item_stop' => '', 'question_start' => '<h4>', 'question_stop' => '</h4>', 'answer_start' => '<p>', 'answer_stop' => '</p>');
             break;
         default:
             $container = array('show_cat_title' => $args['show_cat_title'], 'container_header' => 'h3', 'container_start' => '<ul class="wd-faq wd-faq-list">', 'container_stop' => '</ul>', 'item_start' => '<li>', 'item_stop' => '</li>', 'question_start' => '<strong>', 'question_stop' => '</strong><br />', 'answer_start' => '', 'answer_stop' => '');
     }
     // Frontend output from here
     wddump(array(basename(__FILE__), $container));
     echo $args['before_widget'];
     echo $args['before_title'] . $title . $args['after_title'];
     $container_start = str_replace('%wdcatid%', '', $container['container_start']);
     $terms = get_terms('wdfaq_category');
     wddump(array('Content of $args', $args));
     // here goes the output
     if ('all' == $args['category']) {
         foreach ($terms as $term) {
             if ($container['show_cat_title']) {
                 $faq_title = get_term_by('slug', $term->slug, 'wdfaq_category', 'ARRAY_A');
                 echo '<' . $container['container_header'] . '>' . $faq_title['name'] . '</' . $container['container_header'] . '>';
             }
             echo $container_start . $lnbrk;
             echo wdst_get_faq($term->slug, $container);
             echo $container['container_stop'] . $lnbrk;
         }
     } else {
         wddump(array('Content of $args', $args));
         if ($container['show_cat_title']) {
             // $faq_title = $args['category'];
             $faq_title = get_term_by('slug', $terms[0]->slug, 'wdfaq_category', 'ARRAY_A');
             wddump(array('Content of $faq_title', $faq_title));
             echo '<' . $container['container_header'] . '>' . $faq_title['name'] . '</' . $container['container_header'] . '>';
         }
         echo $container_start . $lnbrk;
         echo wdst_get_faq($args['category'], $container);
         echo $container['container_stop'] . $lnbrk;
     }
     echo $args['after_widget'];
 }
Ejemplo n.º 2
0
/**
 * Create shortcode [faq-categories]
 */
function faq_categories_shortcode($atts)
{
    // Attributes
    extract(shortcode_atts(array('category' => NULL, 'titles' => NULL), $atts));
    $faq_container = array('show_cat_title' => $titles, 'header_start' => '<h3>', 'header_stop' => '</h3>', 'container_start' => '<ul class="wd-faq wd-faq-list" %wdcatid%>', 'container_stop' => '</ul>', 'item_start' => '<li>', 'item_stop' => '</li>', 'question_start' => '<strong>', 'question_stop' => '</strong><br />', 'answer_start' => '', 'answer_stop' => '');
    $returnvalue = '';
    $lnbrk = "\n";
    // $no_title = array(NULL, false, 'No', 'no', 'N', 'n', 0);
    $terms = get_terms('wdfaq_category');
    if (is_null($category) and is_null($titles)) {
        // No category given and no titles to show
        $container_start = str_replace('%wdcatid%', '', $faq_container['container_start']);
        $returnvalue .= $container_start . $lnbrk;
        foreach ($terms as $term) {
            $returnvalue .= wdst_get_faq($term->slug, $faq_container);
        }
        $returnvalue .= $faq_container['container_stop'] . $lnbrk;
    } elseif (is_null($category) and !is_null($titles)) {
        // No category given but titles will show
        foreach ($terms as $term) {
            $faq_title = get_term_by('slug', $term->slug, 'wdfaq_category', 'ARRAY_A');
            $container_start = str_replace('%wdcatid%', 'id = "wd_faq_' . $faq_title['slug'] . '"', $faq_container['container_start']);
            $returnvalue .= $faq_container['header_start'] . $faq_title['name'] . $faq_container['header_stop'] . $lnbrk;
            $returnvalue .= $container_start . $lnbrk;
            $returnvalue .= wdst_get_faq($term->slug, $faq_container);
            $returnvalue .= $faq_container['container_stop'] . $lnbrk;
        }
    } else {
        if (!is_null($titles)) {
            $faq_title = get_term_by('slug', $term->slug, 'wdfaq_category', 'ARRAY_A');
            $returnvalue .= $faq_container['header_start'] . $faq_title['name'] . $faq_container['header_stop'] . $lnbrk;
        }
        $returnvalue .= $faq_container['container_start'] . $lnbrk;
        $returnvalue .= wdst_get_faq(sanitize_title_with_dashes($category), $faq_container);
        $returnvalue .= $faq_container['container_stop'] . $lnbrk;
    }
    return $returnvalue;
}