WordPress.org

Ready to get started?Download WordPress

Forums

Display sub-categories in 2 columns (2 posts)

  1. atdheu
    Member
    Posted 1 year ago #

    Hi,

    Im using below code to display list of subcategories:

    <?php
    if (is_category()) {
    $this_category = get_category($cat);
    }
    if($this_category->category_parent)
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->category_parent."&echo=0"); else
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->cat_ID."&echo=0");
    if ($this_category) { ?>
    <?php echo $this_category; ?>
    <?php } ?>

    How can Idisplay list of subcategories in 2 columns, thanks.

  2. converting2wp
    Member
    Posted 1 year ago #

    See my answer to your other question where I recommended the use of get_categories.

    If you want to fine tune the output of a list of categories, you'll almost certainly want to use one of the WordPress functions, not the template tag wp_list_categories. [Even if you use "echo=0" the return value of wp_list_categories still contains all the HTML for the list, and it'll be difficult to put the <tr></tr> tags where you want them to be.]

    The idea of most template tags is that they handle generating the HTML that's good enough for most folks (e.g. formatting it as a list with the correct links). If you want to do something outside their scope, you'll need to get the "raw" data and then write the code to format the lists to meet your specifications.

    So once you have an array of categories, you can put it into a two-column table, or do other things with it.

    Does that help?

Topic Closed

This topic has been closed to new replies.

About this Topic