Support » Fixing WordPress » New to writing Shortcodes

  • Resolved CallMeAndy

    (@callmeandy)


    Hi dont know if anyone can put me right – a probably a newbie stupid error but…
    writing a shortcode to list child categories based on the name of the page which implements a category and has the same name.
    In this case the Page name is Destinations which is also the name of a top level category.

    function AB_handler_get_child_cats($atts){
    
        $category_name=get_the_title();
        $cat = get_cat_ID($category_name);
    
        if( $cat > 0 ){
    
            extract(shortcode_atts(array(
                        'show_count' => "0",
                        'orderby' =>"name",
                    ), $atts));
    
            $this_category = get_category($cat);
            if (get_category_children($this_category->cat_ID) != "") {
    
                $html = "<div><ul>";
                wp_list_categories("orderby=$orderby&show_count=$show_count&title_li=
                    &use_desc_for_title=1&child_of=".$this_category->cat_ID);
                $html .= "</ul></div>";
            }
            return $html;
        }
    }
    
    add_shortcode('childcats','AB_handler_get_child_cats');

    If I put the following [childcats] or [childcats show_count=1 orderby=’name’] in a text widget titled “Destinations” the output is being rendered prior to the start of the widget border (outside the border).

    What am I doing wrong?

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘New to writing Shortcodes’ is closed to new replies.