Math so that I don't have to keep declaring exact numbers
Page 1 of 1
Interinactive
VIP Member



Posts: 29151

PostPosted: 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
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Thu, 28th Nov 2013 11:18    Post subject:
($item % 6 - 3 == 0 || $item % 6 - 3 == 1)
This should work Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Interinactive
VIP Member



Posts: 29151

PostPosted: 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
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: 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 Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Interinactive
VIP Member



Posts: 29151

PostPosted: 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
PostPosted: 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 Smile

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 Wink
Back to top
Interinactive
VIP Member



Posts: 29151

PostPosted: 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
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: 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 Smile

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 Wink


Why so complicated?
div:nth-child(6n-3),div:nth-child(6n-2){
background: #f00;
}

Razz

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 Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
paxsali
Banned



Posts: 18352

PostPosted: 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
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: 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 Laughing


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
paxsali
Banned



Posts: 18352

PostPosted: 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
Interinactive
VIP Member



Posts: 29151

PostPosted: 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
paxsali
Banned



Posts: 18352

PostPosted: 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
PostPosted: 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
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group