Created
July 9, 2012 09:47
-
-
Save ifthenelse/3075390 to your computer and use it in GitHub Desktop.
A function to set CSS classes to an html element such as "first", "last", "odd", "even" and "active"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Sets classes such as "first", "last", "odd", "even" and "active" | |
* @param $articles An array of articles to count | |
* @param $index The index to watch for | |
* @param $currentArticle The index of the current article | |
* @return string | |
**/ | |
function setCSSClasses($index = null, $articles = null, $currentArticle = null) { | |
return ((is_int($index) && ($index == 1)) ? " first" : "").(((is_int(count($articles))) && ($index == count($articles))) ? " last" : "").((is_int($index) && ($index % 2 == 0)) ? " even" : " odd").(($index == $currentArticle)) ? " active" : ""); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment