Page 1 of 1 |
|
Posted: Thu, 28th Nov 2013 11:11 Post subject: Math so that I don't have to keep declaring exact numbers |
|
 |
I have a bunch of tiles that look like this:
By default the tile sizes are the red, I want to make it so that the blue (3rd, 4th, 9th) are selected and are given another image size to use. Here's how I'm doing it:
Quote: | <?php
$item++;
if ($item == 3 || $item == 4 || $item == 9) {
the_field('featured_image_landscape');
} else {
the_field('featured_image_portrait');
}
?> |
That works in my responsive layout, but it's a bit shit, not as shit as my math skills though. Is there some sort of calculation I can use here to ensure that pattern repeats no matter how many I add?
Eg: if ($item =holyshitballsrepeatingcalculation) instead of 3, 4, 9 etc
The pattern will remain as per the image above, big image on right, then left, right, left, right etc
Thanks for any help
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 11:18 Post subject: |
|
 |
($item % 6 - 3 == 0 || $item % 6 - 3 == 1)
This should work 
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 11:32 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:45; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 11:37 Post subject: |
|
 |
Even shorter:
the_field(($i%6-3) >> 1 == 0?'featured_image_landscape':'featured_image_portrait');
no more if required 
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 11:50 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:45; edited 1 time in total
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Thu, 28th Nov 2013 11:54 Post subject: |
|
 |
You can actually do that in pure CSS too if you're willing use an additional wrapper
Code: |
.wrapper:nth-child(odd) .item:nth-child(3),
.wrapper:nth-child(even) .item:nth-child(1) {
.big-style;
}
|
3rd item in odd rows, 1st in even rows 
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 12:01 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:45; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 13:00 Post subject: |
|
 |
Werelds wrote: | You can actually do that in pure CSS too if you're willing use an additional wrapper
Code: |
.wrapper:nth-child(odd) .item:nth-child(3),
.wrapper:nth-child(even) .item:nth-child(1) {
.big-style;
}
|
3rd item in odd rows, 1st in even rows  |
Why so complicated?
div:nth-child(6n-3),div:nth-child(6n-2){
background: #f00;
}
Edit: Aaaand a bit shorter:
<?php the_field((++$item%6-3)>>1?'featured_image_portrait':'featured_image_landscape'); ?> <- this should replace the whole file you had up there 
|
|
Back to top |
|
 |
|
Posted: Thu, 28th Nov 2013 18:31 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 22:04; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Fri, 29th Nov 2013 13:31 Post subject: |
|
 |
Yeah, I wasn't remembering how to properly mask that stuff because masking/shifting the bits was nothing that I do normally 
|
|
Back to top |
|
 |
|
Posted: Fri, 29th Nov 2013 14:12 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 22:04; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Fri, 29th Nov 2013 22:52 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:45; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Sat, 30th Nov 2013 18:26 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 22:04; edited 1 time in total
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Sat, 30th Nov 2013 19:03 Post subject: |
|
 |
paxsali wrote: | only few langs support bitmasking "&". |
Eh? Anything that supports shifting supports masking as well, at least I haven't found any language that doesn't yet. In fact, I'm pretty there isn't a language out there that doesn't? Masks and shifts are used so much internally that I can't see how they wouldn't include them.
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |