• Resolved alexleonard

    (@alexleonard)


    As I’m not very strong on PHP, I thought I’d ask here for some help.

    I’m trying to sort out a way of displaying my links from one category, but in three columns. As this list is going to be expanding I need to code this in a future proof way.

    I’m thinking that the best way to do this would be to use the get_bookmarks function to return an array of my bookmarks. I could then analyse the array, work out how many bookmarks are in it, divide by 3, and then display that number of bookmarks in each column, being careful to avoid any duplication.

    Problem is I haven’t the first notion of how I would go about doing this!

    Here’s my english/code demo:

    <?php
    $array = get_bookmarks('category=1');
    $columnlength = $array/3;
    ?>
    
    <div class="col1">
    wp_list_bookmarks('limit=$columnlength');
    </div>
    
    <!-- As there's no offset function so I don't know what to do for columns 2 and 3 -->
    <div class="col2">
    wp_list_bookmarks('limit=$columnlength');
    </div>
    
    <div class="col3">
    wp_list_bookmarks('limit=$columnlength');
    </div>

    I am assuming that I’m going to need to do something a little more sophisticated and outside of the get_bookmarks/wp_list_bookmarks functions..?

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thanks for this useful thread! I have tried the 3-column solution. Somehow it doesn’t accept $columnlength*2
    in

    <div class="col3"><?php wp_list_bookmarks(array(
    'limit'=>$columnlength*2.','.$columnlength,
    'category'=>1,
    ) ); ?></div>

    I am receiving an parse error “Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘)’ ..” caused by $columnlength*2.

    Does anybody know what the error in the syntax is? Thanks in advance …

    Could someone please post how they managed to get it to work with 3 or more columns?

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Need PHP help for sorting an array’ is closed to new replies.