We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

FF Matrix Offset Calculation

Development and Programming

BC Team's avatar
BC Team
244 posts
16 years ago
BC Team's avatar BC Team

I’m creating a gallery using FF Matrix and would like segment_4 to set which photo is displayed. I’m doing the following:

{myImages  limit="1" offset="{segment_4}"}

{imageUrl}

{/myImages}

This however means that the url: mysite.com/photos/my-gallery/0 will show image no. 1 and mysite.com/photos/my-gallery/5 will show image no. 4 etc.

I’d really like the URL to match the image number something like the following would work but it doesn’t.

{myImages  limit="1" offset="{exp:simple_math calculate='{segment_4}-1'}"}

{imageUrl}

{/myImages}

I’ve seen examples using row_count to show a single image but this means the code has to loop through all the images, not as efficient

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
16 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

If you turn on PHP on input mode you can achieve the “minus one” math that way.

{myImages  limit="1" offset="{exp:simple_math calculate='<?={segment_4}-1;?>'}"}

{imageUrl}

{/myImages}

Give that a shot and see if it works.

       
BC Team's avatar
BC Team
244 posts
16 years ago
BC Team's avatar BC Team

Yep that worked like this:

{myImages  limit="1" offset="<? {segment_4}-1 ?>"}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.