• I am having a really difficult time figuring this out, I’ve spent hours googling and looking through the forums.

    What I am trying to do is sort my category lists in a certain order.
    Right now it is showing the columns as:

    1 2
    3 4
    5 6
    7 8

    What I am trying to achieve is:

    1 5
    2 6
    3 7
    4 8

    Full Code is located here:
    https://pastebin.com/HQvRuJH1

    Here is a snippet:

    <?php
    if($this_category->category_parent)
    $this_category = wp_list_categories('orderby=name&show_count=0
    &title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.
    "&echo=0"); else
    $this_category = wp_list_categories('orderby=name&depth=n&show_count=0
    &title_li=&use_desc_for_title=1&child_of=47'.$this_category->cat_47.
    "&echo=1");
    if ($this_category) {
    printf( $this_category );
    }?>

    But I cannot fit much of it without pastebin.

    Any help would be great appreciated !

Viewing 8 replies - 1 through 8 (of 8 total)
  • I am not sure this is exactly what you need, but…
    The example how to split category list into two lists (or columns). Use get_categories() instead of wp_list_categories() in this method.

    $allcats = get_categories();
    $catlists = array_chunk($allcats, ceil(count($allcats) / 2 ));
    foreach ($catlists as $catlist) :
        echo '<ul>';
        foreach($catlist as $category) :
    	echo '<li>' . $category->name . '</li>';
        endforeach;
        echo '</ul>';
    endforeach;

    Thread Starter espnicholas

    (@espnicholas)

    Hello vjpo,

    Thanks for the reply, basically i’m trying to format the columns so it doesn’t go left to right, left to right as the example

    1 2
    3 4
    5 6

    I am trying to achieve it to become a vertical column that would be

    1 4
    2 5
    3 6

    the numbers represent each category.

    On the code you gave me it currently achieves the samething. I have the columns I just need them to be sorted the correct way. Using your method though it listed all the categories if I were to use that where would I say define a child and parent and the ID?

    Hello, Espnicholas!
    As I understood, you want to sort the list because there is so many categories in it, to use a full width of a page.
    I don’t know how to divide list produced by wp_list_categories() into two columns.
    This method splits list, so you can wrap parts in div’s and show them as you wish.
    Check the reference about get_categories(); parameters and how to retrieve ID, parent, link or name
    https://codex.www.ads-software.com/Function_Reference/get_categories

    One thing is complicated – to show the hierarchy of categories.

    Thread Starter espnicholas

    (@espnicholas)

    Well kind of, I am using two columns at the moment that are centered in the page. Everything is working with the name, post numbers, etc .. and on other pages the child categories also. It’s just the column sorting that’s giving me a giant headache.

    It’s possible with wp_list_categories()
    link 1, link 2

    Thread Starter espnicholas

    (@espnicholas)

    Thanks for the link! I will look through these and see if I can figure it out. Thanks a ton for all your help.

    Say thanks for links to google ??
    You are welcome ??

    Thread Starter espnicholas

    (@espnicholas)

    Finally figured it out thanks to your second link. The person that posted it thanked the person for his original source code which happens to be located here buried 2 years ago. For feature reference for anyone this is the link to it:
    https://www.ads-software.com/support/topic/2-or-3-column-categories-in-sidebar?replies=39#post-1203083

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘2 Columns – Category List Sorting’ is closed to new replies.