Home > Enterprise >  Echo wp_list_categories and exclude categories from list
Echo wp_list_categories and exclude categories from list

Time:10-18

I want a title above the wordpress categories lists but for that I need to split the categories list in 2 lists.

        $projectCats = wp_list_categories($args);
    ?>
    <div >Zakelijk
    <ul class=>
        <?php echo $projectCats; ?>
    </ul>
    <div >Particulier</div>
        <ul class=>
        <?php echo $projectCats; ?>
    </ul>
    </div>

this is the code I use right now and now I just need to exclude categories in the first echo and the second echo. I don't understand php only html and css, at the original wordpress I saw:

excludeint[]|string Array or comma/space-separated string of term IDs to exclude. If $hierarchical is true, descendants of $exclude terms will also be excluded; see $exclude_tree. See get_terms() .

Maybe I can use that somehow? Please let me know if you need more information.

CodePudding user response:

You need to use the exclude argument to add the category Ids you want to exclude from the list. After that you can make two lists with it.

You can find the Ids of the categories in the URL in the backend. For example: /wp-admin/term.php?taxonomy=category&tag_ID=12

You need the tag_ID.

Like this:

<div >Zakelijk
    <ul>
    <?php
        $projectCats1 = wp_list_categories(
            array(
                'exclude'  => array( 4,7 ),
                'title_li'  => '',
            )
        );
    ?>
    </ul>
</div>
<div >Particulier</div>
    <ul>
        <?php
            $projectCats2 = wp_list_categories(
                array(
                    'exclude'  => array( 12,16 ),
                    'title_li'  => '',
                )
            );
        ?>
    </ul>
</div>

More about the function here.

  • Related