Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding first and last classes to widgets

  • Loading branch information...
commit f383bc013eb5204cd4ed621faad6317b35d6fb3c 1 parent 95b6501
Ben Word retlehs authored

Showing 1 changed file with 36 additions and 0 deletions. Show diff stats Hide diff stats

  1. +36 0 inc/roots-cleanup.php
36 inc/roots-cleanup.php
@@ -465,4 +465,40 @@ function roots_body_class() {
465 465 return;
466 466 }
467 467
  468 +// first and last classes for widgets
  469 +// http://wordpress.org/support/topic/how-to-first-and-last-css-classes-for-sidebar-widgets
  470 +function roots_widget_first_last_classes($params) {
  471 + global $my_widget_num;
  472 + $this_id = $params[0]['id'];
  473 + $arr_registered_widgets = wp_get_sidebars_widgets();
  474 +
  475 + if (!$my_widget_num) {
  476 + $my_widget_num = array();
  477 + }
  478 +
  479 + if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) {
  480 + return $params;
  481 + }
  482 +
  483 + if (isset($my_widget_num[$this_id])) {
  484 + $my_widget_num[$this_id] ++;
  485 + } else {
  486 + $my_widget_num[$this_id] = 1;
  487 + }
  488 +
  489 + $class = 'class="widget-' . $my_widget_num[$this_id] . ' ';
  490 +
  491 + if ($my_widget_num[$this_id] == 1) {
  492 + $class .= 'widget-first ';
  493 + } elseif ($my_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) {
  494 + $class .= 'widget-last ';
  495 + }
  496 +
  497 + $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']);
  498 +
  499 + return $params;
  500 +
  501 +}
  502 +add_filter('dynamic_sidebar_params', 'roots_widget_first_last_classes');
  503 +
468 504 ?>

0 comments on commit f383bc0

Please sign in to comment.
Something went wrong with that request. Please try again.