I've got the following question which I can''t figure out.
For example: I have 9 list items in one ul list. The li items have float:left (css) and are visible in 3 columns.
list item 1 list item 2 list item 3
list item 4 list item 5 list item 6
list item 7 list item 8 list item 9
I would like to point out that I've added the number of each list item as classname, so it is possible to identify each item.
Is it possible (through php, javascript, jquery etc) to calculate that list-item 5 in a 3 column layout would be positioned in column 2. As a result the number "2" is needed?
The following code snippets may help you,
<?php
function get_column_val($needle, $total_columns) {
if (($column_no = ($needle%$total_columns)) == 0) {
$column_no = $total_columns;
}
return $column_no;
}
for ($i = 1; $i < 10; $i++) {
$col_no = get_column_val($i, 3);
echo "$i -> $col_no";
echo "<br />";
}
?>
You can use get_column_val
function, to find column no.
echo get_column_val(1, 3); // returns 1
echo get_column_val(2, 3); // returns 2
echo get_column_val(3, 3); // returns 3
echo get_column_val(4, 3); // returns 1