Posted By

nijgnet on 02/25/08


Tagged

css wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Wiederkehr
basicmagic


Remove leftmost and rightmost padding in LI output


 / Published in: PHP
 

Inserts "first" and "last" classes to the first and last items respectively. "first" and "last" classes defined in CSS as without padding.

  1. /*
  2.  * Applies pseudo-pseudo classes to inline list items.
  3.  * Mainly used for autogenerated subnavs.
  4.  *
  5.  * @param $the_list String: html code of <li> elements
  6.  * @param $first Bool: apply style to the first <li>
  7.  * @param $last Bool: apply style to the last <li>
  8.  * @return $the_list String: modified html code
  9.  */
  10. function remove_padding_li ($the_list, $first=FALSE, $last=FALSE)
  11. {
  12. if ($first) {
  13. $the_list = preg_replace('/^<li class=\"/i', '<li class="first ', $the_list);
  14. }
  15. if ($last) {
  16. $the_list = preg_replace('/<li class=\"(.*)$/i', '<li class="last $1', $the_list);
  17. }
  18. return $the_list;
  19. }

Report this snippet  

You need to login to post a comment.