I have a homepage template that I manually change and there are rows with 3 columns each. Each column is a topic with entries.
I wrote out some PHP to programmatically to create these rows and columns so that I could query the database and then create the columns much easier.
It basically takes the array of items, and breaks into smaller items.
The problem I'm having is converting it to work with EE and the template engine.
I started out by creating a plugin, and maybe this isn't the way to do it. I can get the topics and spit them out using the parse_variables function in the template engine. Getting them into their own arrays like I do in my test code below isn't hard, but I'm not certain how to get this working within the plugin and the EE template.
Then I just use:
{exp:topics_loop:all}
{topics}
{topic}
{topics}
{/exp:topics_loop:all}
It spits out the topics, yay, but that's easy. Anyway, here's my rudimentary test code to get a better idea of what I'm trying to accomplish:
<?php
$array = array();
for( $i = 1; $i <= 13; $i++ ) {
array_push($array, 'topic ' . $i);
}
$thisArray = array();
$numPerRow = 3;
$numElems = count($array);
$rowCount = 0;
$thisArray[] = array();
foreach( $array as $key => $value ) {
if( count($thisArray[$rowCount]) == $numPerRow ) {
if( ($numElems - $key) == 4) {
$numPerRow = 2;
}
$rowCount++;
}
$thisArray[$rowCount][] = $value;
}
foreach($thisArray as $arrays) {
echo 'start row<br />';
$count = count($arrays);
if( $count == 3) {
foreach($arrays as $a) {
echo 'span_4 - ' . $a . '<br />';
}
}
if( $count == 2 ) {
foreach($arrays as $a) {
echo 'span_6 - ' . $a . '<br />';
}
}
echo 'end row<hr />';
}
I create a simple array of items just for testing out different combinations. It creates columns of 3, if it has 1 item in the last array, we split the last 2 into arrays of 2. I never want 1 item by itself essentially.
If you run this specific code, you'll see that it creates:
start row
span_4 - topic 1
span_4 - topic 2
span_4 - topic 3
end row
start row
span_4 - topic 4
span_4 - topic 5
span_4 - topic 6
end row
start row
span_4 - topic 7
span_4 - topic 8
span_4 - topic 9
end row
start row
span_6 - topic 10
span_6 - topic 11
end row
start row
span_6 - topic 12
span_6 - topic 13
end row
Anyway, this is rudimentary, but if anyone has pointers on how to get this idea into EE, let me know.
Thanks.