Jump to content

Recommended Posts

Posted

Hi,
I need to print in alternation a different markup such as :

Markup1 for item 1
Markup2 for item 2
Markup1 for item 3
Markup2 for item 4

I tried different versions since I was thinking having found solution on previous posts, but it didn't do as I want. Or it print a class odd-even in a div or print the same markups but reordering as item 1, 3, 5, 2, 4, 6.
Thanks!
Mel

 

Posted

The solutions pointed on those threads seem to point the right way to what you want to do, maybe if you could post some code?

Posted

Yeah, sure.

	$odd = '';
	$even = '';
		foreach ($page->plus as $key => $projet) {
		    if ($key % 2) {
		        $even .= "some html code : A";

		    } else {
		        $odd .=	"some html code (not the same) : B";
		    }
		}

		$content .=  $odd;
		$content .=  $even;

But I end up with B, B, B, A, A, A

I want B, A, B, A, B, A.

I'm close, but not exactly what I need. I understand why, but I don't where add $content. Do I need an other loop at the end? Or it shouldn't be a if/else?
Thanks

Posted
$content = "";
foreach ($pages->plus as $key => $projet) {
    if ($key % 2) {
        $content .= "A";

    } else {
        $content .=	"B";
    }
}
		
echo $content;

Can you try this?

  • Like 1
  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...