Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I need to merge this:
- <?php
- if (is_category()) {
- $this_category = get_category($cat);
- if (get_category_children($this_category->cat_ID) != "") {
- echo '<h3 class="widget-title">Cities in ';
- echo single_cat_title(); ;
- echo '</h3>';
- echo '<ul class="xoxo categories">';
- wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);
- echo "</ul>";
- }
- }
- ?>
- with this:
- <?php // display categories list in 5 columns
- // Grab the categories - top level only (depth=1)
- $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&show_count=1&exclude=1' );
- // 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 class="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>
- so that I end up with a 5 column list of the sub categories for the currently viewed category
- I've solved it, Praise the Lord
- <?php // display categories list in 5 columns
- // Grab the categories - top level only (depth=1)
- $this_category = get_category($cat);
- $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&show_count=1&exclude=1&child_of='.$this_category->cat_ID);
- // 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 class="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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement