Keyword

K2 content module: echo something if last item is odd number

  • Neppers
  • Neppers's Avatar Topic Author
  • Offline
  • New Member
More
9 years 6 months ago #142347 by Neppers
Is it possible in the k2 content module to echo something if the last item is of a odd number? I am echoing a closing div after every even number, but if the last item is a odd number I also need the closing div in that one.

:-)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 6 months ago - 9 years 6 months ago #142361 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 content module: echo something if last item is odd number
Hello,
<?php echo ($key%2 && count($items)==$key+1 ) ? "</div>" : " "; ?>

The closing tag will be printed only if it is the last tag AND it is an odd number.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 9 years 6 months ago by Krikor Boghossian.

Please Log in or Create an account to join the conversation.

  • Neppers
  • Neppers's Avatar Topic Author
  • Offline
  • New Member
More
9 years 6 months ago #142371 by Neppers
Thanks. It did not get your code to work, though I see the idea.

This fixed it, but I guess it is the not best code:

<?php if(count($items)): ?>
<?php if(is_int($key%2/2) && (count($items)==$key+1))
{
echo("</div>");
}
?>
<?php endif; ?>

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 6 months ago #142385 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 content module: echo something if last item is odd number
It 's the same code basically and I would not say it's ugly or unreadable.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum