Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.54 KB | None | 0 0
  1. I need to merge this:
  2.  
  3.  
  4.     <?php
  5.             if (is_category()) {
  6.               $this_category = get_category($cat);
  7.               if (get_category_children($this_category->cat_ID) != "") {
  8.                 echo '<h3 class="widget-title">Cities in ';
  9.                  echo single_cat_title(); ;
  10.                 echo '</h3>';
  11.                 echo '<ul class="xoxo categories">';
  12.                 wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);
  13.                 echo "</ul>";
  14.               }
  15.             }
  16.             ?>
  17.  
  18.  
  19.  
  20. with this:
  21.  
  22.  
  23. <?php // display categories list in 5 columns
  24.                 // Grab the categories - top level only (depth=1)
  25.                  $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&show_count=1&exclude=1' );
  26.                 // Split into array items
  27.                  $cat_array = explode('</li>',$get_cats);
  28.                 // Amount of categories (count of items in array)
  29.                  $results_total = count($cat_array);
  30.                 // How many categories to show per list (round up total divided by 5)
  31.                  $cats_per_list = ceil($results_total / 5);
  32.                 // Counter number for tagging onto each list
  33.                  $list_number = 1;
  34.                 // Set the category result counter to zero
  35.                  $result_number = 0;
  36.             ?>
  37.             <ul class="category_footer_post" id="cat-col-<?php echo $list_number; ?>">
  38.            
  39.                 <?php
  40.                     foreach($cat_array as $category) {
  41.                     $result_number++;
  42.            
  43.                     if($result_number % $cats_per_list == 0) {
  44.                     $list_number++;
  45.                     echo $category.'</li>
  46.                    </ul>
  47.            
  48.                    <ul class="category_footer_post" id="cat-col-'.$list_number.'">';
  49.            
  50.                 } else { echo $category.'</li>'; } } ?>
  51.            
  52.             </ul>
  53.  
  54.  
  55.  
  56. so that I end up with a 5 column list of the sub categories for the currently viewed category
  57.  
  58.  
  59.  
  60.  
  61. I've solved it, Praise the Lord
  62.  
  63.         <?php // display categories list in 5 columns
  64.                 // Grab the categories - top level only (depth=1)
  65.                 $this_category = get_category($cat);
  66.                  $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&show_count=1&exclude=1&child_of='.$this_category->cat_ID);
  67.                 // Split into array items
  68.                  $cat_array = explode('</li>',$get_cats);
  69.                 // Amount of categories (count of items in array)
  70.                  $results_total = count($cat_array);
  71.                 // How many categories to show per list (round up total divided by 5)
  72.                  $cats_per_list = ceil($results_total / 5);
  73.                 // Counter number for tagging onto each list
  74.                  $list_number = 1;
  75.                 // Set the category result counter to zero
  76.                  $result_number = 0;
  77.             ?>
  78.             <ul class="category_footer_post" id="cat-col-<?php echo $list_number; ?>">
  79.            
  80.                 <?php
  81.                     foreach($cat_array as $category) {
  82.                     $result_number++;
  83.            
  84.                     if($result_number % $cats_per_list == 0) {
  85.                     $list_number++;
  86.                     echo $category.'</li>
  87.                    </ul>
  88.            
  89.                    <ul class="category_footer_post" id="cat-col-'.$list_number.'">';
  90.            
  91.                 } else { echo $category.'</li>'; } } ?>
  92.            
  93.             </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement