bwakad Posted March 31, 2014 Share Posted March 31, 2014 Not sure if someone already have this, but I just wanted to share it, hoping someone improve it, maybe it's good for a function? It will split long list of pages first top to bottom, then left to right. columns are chosen by you. A | D | G B | E | H C | F | I $columns = 3; // choose number of columns $item = 0; // set counter to zero $num = $pages->count("parent=/branche/"); // use variable for total pages $itemsInColumn = intval($num / $columns); // calculate how many child-pages per column echo "total: ". $num . " | per column: " . $itemsInColumn . "<br />"; // this can be removed if you don't want echo "<div class='left'>"; // left is css: float left foreach($pages->find("parent=/branche/") as $child) { $item ++; // count for each child-page a plus one if($item > $itemsInColumn) { $item = 1; // set back to 1 if total is larger then total in column echo "</div>"; // then end div echo "<div class='left'>"; // and start new float left } echo "<a href='{$child->url}'>{$child->title}</a><br />"; // output my child-page } echo "</div><div class='clear'></div>"; // clear float, end div I know you all must have this, but I am really starting to be afraid asking so I found out by myself 8 Link to comment Share on other sites More sharing options...
Valery Posted April 1, 2014 Share Posted April 1, 2014 Classic stuff, bwakad! Goes well with blogs and shops. Thanks for the code, Take care ! Link to comment Share on other sites More sharing options...
phil_s Posted June 20, 2014 Share Posted June 20, 2014 Very useful piece of code indeed, thank you! It kind of goes haywire if $itemsInColumn is uneven though. Using ceil($num / $columns); instead of intval($num / $columns); fixed it for me! cheers phil 2 Link to comment Share on other sites More sharing options...
bwakad Posted June 21, 2014 Author Share Posted June 21, 2014 thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now