• Hi everybody!

    I need order categories in 4 columns in this code:

    <div id="listprovinces"><?php wp_list_categories('title_li=<h2>Provinces</h2>&sort_column=name&show_count=0&hide_empty=0&show_option_all&child_of=0&exclude_tree=1&depth=1&exclude=1,33,34,35,467'); ?></div>

    like this…

    1 4 7 10
    2 5 8 11
    3 6 9 12

    it’s possible? thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter vektorlab

    (@vektorlab)

    i resolved it! but i need this in a shortcode of functions.php. someone can help me please?

    <?php
    // Grab the categories - top level only (depth=1)
     $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&sort_column=name&show_count=0&hide_empty=0&show_option_all&child_of=0&exclude_tree=1&exclude=1,33,34,35,467' );
    // Split into array items
     $cat_array = explode('</li>',$get_cats);
    // Amount of categories (count of items in array)
     $results_total = count($cat_array);
    // How many categories to show per list (round up total divided by 5)
     $cats_per_list = ceil($results_total / 5);
    // Counter number for tagging onto each list
     $list_number = 1;
    // Set the category result counter to zero
     $result_number = 0;
    ?>
    
    <ul id="category_footer_post" id="cat-col-<?php echo $list_number; ?>">
    
        <?php
            foreach($cat_array as $category) {
            $result_number++;
    
            if($result_number % $cats_per_list == 0) {
            $list_number++;
            echo $category.'</li>
            </ul>
    
            <ul class="category_footer_post" id="cat-col-'.$list_number.'">';
    
        }
    
        else {
    
            echo $category.'</li>';
    
            }
    
        } ?>
    
    </ul>
Viewing 1 replies (of 1 total)
  • The topic ‘order of wp_list_categories’ is closed to new replies.