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:


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:


$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;
    $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.



I would start by looking at the Matrix add-on. This may help solve your problem. Matrix

  • I'll look into it. I'm not really wanting to add another third party plugin into the mix. Thanks. – Erik Apr 5 '13 at 14:05
  • Yea, I looked into it. It's not really what I'd want or need. It's much more than I need to be honest and a custom plugin which tailors to my needs is the way to go. I just need to figure out how to convert my working PHP into a plugin for EE. Thanks for your insight. – Erik Apr 5 '13 at 18:39
  • Great. If you think your plugin would help others, write some docs and offer it on devot-ee.com. – 4midori Apr 5 '13 at 22:07
  • It would be great, however, the reason I came on here was to get some pointers on how to convert my straight PHP into a plugin for EE. Any ideas? – Erik Apr 8 '13 at 12:37
  • Sorry, I didn't read your response carefully - that's beyond my skillset. Try posting this Q to Twitter w/ #eecms tag. – 4midori Apr 8 '13 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.