Forums

Help: Display Category list in 2 columns (6 posts)

  1. 5hashank
    Member
    Posted 1 year ago #

    I have a long list of categories. When I use the widget "Categories" the list scrolls down to the page. I want to display the list in 2 or 3 columns in the sidebar to improve the aesthetics.

    Please Help.

    Thank You.

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    you could try to apply a fixed width (just less than 50%/33% resp) and a 'float:left' to the category list elements;

    details depend on your setup; a link to your site might help.

  3. 5hashank
    Member
    Posted 1 year ago #

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    with that code, you would need to edit sidebar.php,
    find a space that is shown even if you use widgets (either below or above the widgetized area),
    and then add it there,
    probably adjusting it to stay in keeping with your design.

  5. 5hashank
    Member
    Posted 1 year ago #

    Got it :)
    Can you tell me how to edit the css ?

    We can now easily style following with CSS: #cat-col-'.$list_number.' with '.$list_number.' being the… you guessed it, the number of your column.
    Because every column will have its own number, do not forget that you will have to style all columns (#cat-col-1, #cat-col-2, #cat-col-3, #cat-col-4, #cat-col-5).

    Thank You

  6. 5hashank
    Member
    Posted 1 year ago #

    After banging my head against the wall several times I finally found a really nice solution to this problem..

    Downloaded the Custom Widget Plugin from here

    Then added a widget with the following code:

    <?php
    $cats = explode("
    ",wp_list_categories('title_li=&echo=0&depth=1&style=none'));
    $cat_n = count($cats) - 1;
    for ($i=0;$i<$cat_n;$i++):
    if ($i<$cat_n/2):
    $cat_left = $cat_left.'

  7. '.$cats[$i].'
  8. ';
    elseif ($i>=$cat_n/2):
    $cat_right = $cat_right.'
  9. '.$cats[$i].'
  10. ';
    endif;
    endfor;
    ?>
    <ul class="left">
    <?php echo $cat_left;?>

    <ul class="right">
    <?php echo $cat_right;?>

    Joy :D

Topic Closed

This topic has been closed to new replies.

About this Topic