Results 1 to 4 of 4

Thread: How to create an ordered list of Ad categories.

  1. #1
    Thread Starter
    Veteran bleem's Avatar
    Join Date
    Feb 2012
    Posts
    1,572
    Thanks
    103
    Thanked 205 Times in 180 Posts

    How to create an ordered list of Ad categories.

    Well I have been wanting to find out what all my category id's are for parent and child ad categories.

    Couldn't find a plugin do do this,but did find this code which has been very useful as I can now add and keep this in a spreadsheet for usage whenever I like.

    Found on stack exchange.

    It might be useful for someone who wants to do this. It certainly helped me do it in seconds.

    Just add this code to your child themes functions.php file.

    Code:
    function show_categories($atts, $content) {
        extract( shortcode_atts( array('taxonomy' => 'ad_cat'), $atts ) );
        $cats = get_categories(array('taxonomy' => $taxonomy,'hide_empty' => 0, 'hierarchical' => 0, 'parent' => 0));
        return show_categories_level($cats, '', '', $taxonomy);
    }
    
    function show_categories_level($cats, $names, $ids,$taxonomy) {
        $res = '<ol>';
        foreach ($cats as $cat) {
            if($names)$n = "$names, $cat->name"; else $n = $cat->name;
            if($ids)$i = "$ids, $cat->term_id"; else $i = $cat->term_id;    
            $res = $res."<li>$n : $i</li>";
            $kittens = get_categories(array('taxonomy' => $taxonomy,'hide_empty' => 0, 'hierarchical' => 0, 'parent' =>$cat->term_id));
            if($kittens) {
                $res .= ("<li>".show_categories_level($kittens, $n, $i, $taxonomy)."</li>");
            }
        }
        return $res."</ol>";
    }
    add_shortcode('show-categories', 'show_categories');
    Then add this shortcode to a new page of your choosing.
    <h2>Default Categories</h2>
    [show-categories]

    I just made a new page called catlist. Then visit this page to see all your ad cats and sub cats in an ordered list with their corresponding id's.

    Good eh!

  2. #2
    daftplay's Avatar
    Join Date
    May 2014
    Location
    Melbourne
    Posts
    82
    Thanks
    9
    Thanked 3 Times in 3 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  3. #3
    Thread Starter
    Veteran bleem's Avatar
    Join Date
    Feb 2012
    Posts
    1,572
    Thanks
    103
    Thanked 205 Times in 180 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  4. #4
    daftplay's Avatar
    Join Date
    May 2014
    Location
    Melbourne
    Posts
    82
    Thanks
    9
    Thanked 3 Times in 3 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Refine Search. Instead of Long list create a staggered list by Category/subcategory
    By f1trader in forum Vantage General Discussion (Legacy)
    Replies: 3
    Last Post: April 25th, 2014, 08:28 AM
  2. [SOLVED] Vantage Directory Categories - How can I create a list of categories in bulk?
    By angusmacisaac in forum Help Using Vantage (Legacy)
    Replies: 2
    Last Post: December 2nd, 2013, 08:03 AM
  3. Samcy Create a Plan or Membership to list in certain categories
    By frcamp in forum Help Using ClassiPress
    Replies: 8
    Last Post: August 19th, 2013, 02:29 PM
  4. Create checkbox list of tags on "Create Listing"
    By sota35 in forum Vantage General Discussion (Legacy)
    Replies: 3
    Last Post: March 15th, 2013, 11:34 AM
  5. [TUTORIAL] Method to take an ordered list and convert to a comma separated list automatically.
    By bleem in forum ClassiPress General Discussion
    Replies: 0
    Last Post: January 25th, 2013, 03:58 PM