Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following foreach witch gets all the content in several groups. I am using Magic Fields.

 <?php $omtaleseksjoner = get_group('Seksjoner');
foreach($omtaleseksjoner as $seksjoner){ 
    echo "<h3>" . $seksjoner['sectiontitle'][1] . "</h3>";
    echo $seksjoner['sectioncontent'][1];
} 
?>

I have usually 5 groups in this foreach, and I want to break it off in two places.

Is it possible to insert other content e.g. after group 2 and 4 ?

Thanks

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can keep tracks of number of cycles and run extras when counter matches. Something like this:

$array  = array(1,2,3,4,5);

$i = 0;

foreach($array as $set) {

    if(2 == $i)
        echo 'after 2';

    if(4 == $i)
        echo 'after 4';

    echo $set;

    $i++;
}

I must note that this is more of PHP basics and really has nothing to do with WordPress. I highly recommend PHP documentation as first stop for such.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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