I wrote a small plugin that enables the usage of basic mathematical (arithmetic) operations (e.g. + - * / )
It can be useful especially in conjunction with conditional ({if}) statements.
The plugin takes 2 parameter, num1 and num2, which are the numbers you want to do something with
Call
{exp:math:add num1="10" num2="2"}
to add 2 and 10 (10+2)
{exp:math:subtract num1="10" num2="2"}
to subtract 2 from 10 (10-2)
{exp:math:multiply num1="10" num2="2"}
to multiply 10 and 2 (10*2)
{exp:math:divide num1="10" num2="2"}
to divide 10 by 2 (10/2)
Mark, but here’s an example usage let’s assume you have a page with list of weblog entries on a single-page entry and you want to highlight the titles of previous and next entry. Let’s also assume you supply entry_id in URL
the code would look like
{exp:weblog:entries entry_id="{segment_3}"}
{body}
{/exp:weblog:entries}
Now list all entries:
<ul>
{exp:weblog:entries entry_id="{segment_3}"}
<li>
<a href="http://{path=site/{entry_id}}">{title}</a>
{if "{entry_id}"=="{exp:math:subtract num1="{segment_3}" num2="1"}"} - this is prev entry
{if "{entry_id}"=="{exp:math:add num1="{segment_3}" num2="1"}"} - this is next entry
</li>
{/exp:weblog:entries}
</ul>
Note that I did not check this example yet
ANOTHER EXAMPLE I used the plugin to make prev/next links for Solspace Gallery Extended. I have only one gallery, but the pictures are linked to different entries, so regular prev/next linking does not work for me. So I have in CSS
.navlink {
display: none;
}
and in template
{exp:gallery_extended:entries related_id="{segment_4}" type="weblog" disable="member_fields|date_fields"}
{if gallery_entry_id < segment_3}
<a href="http://{path=" class="navlink">prev</a>
{/if}
{if gallery_entry_id == segment_3}
[removed]
$(document).ready(function() {
$('#navlink{exp:math:subtract num1="{count}" num2="1"}').css('display', 'inline');
$('#navlink{exp:math:add num1="{count}" num2="1"}').css('display', 'inline');
});
[removed]
{/if}
{if gallery_entry_id>segment_3}
<a href="http://{path=" class="navlink">next</a>
{/if}
{/exp:gallery_extended:entries}
Note that you must use jQuery, have image ID in segment_3 and related weblog entry in segment_4
Ah I kind of see some uses for this now although not entirely sure the next / previous links would work in all cases seeing as how most sites have more than one weblog so just taking off or adding one to the current entry_id wouldn’t necessarily mean that you would end up with the id of the previous or next entry in that weblog.
Having said that I think I can see a couple of uses for this in the future so thanks for giving this away to the community.
Best wishes,
Mark
Hi, I’m using it on my photoblog and it’s awesome. Maybe in the next update you could add increment options like {exp:math:increment num1="1" num2="9"} being num1 where you start and num2 where you end. Keep up the good work and thanks!
Depending on what you’re trying to do then the Loop Plugin might help you out on that side of things.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.