WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove category from wp_category_list (3 posts)

  1. CHEWX
    Member
    Posted 1 year ago #

    I have this code to display all my categories in columns.

    I want to remove one of these categories from the list as it's hidden content.

    How would I do so ?

    <?php
    				// Grab the categories - top level only (depth=1)
    				 $get_cats = wp_list_categories( 'echo=0&title_li=&depth=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 / 4);
    				// 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>';
    
                        }
    
                    } ?>
  2. potentweb
    Member
    Posted 1 year ago #

    $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1' );
    Change to:
    $get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&exclude=' );
    Add the category ID you want to exclude.

  3. CHEWX
    Member
    Posted 1 year ago #

    Fantastic.

    Should have known that myself.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.