add_cssclass( string $class_to_add, string $classes ): string

将 CSS 类添加到字符串。

参数

$class_to_add string 必需
要添加的 CSS 类。

$classes string 必需
要将 CSS 类添加到的字符串。

返回

string 添加了 CSS 类的字符串。

用户贡献的笔记

处理菜单顺序时的用法。

$firstm = $lastm = false;  
$i = 0;    
foreach ( $menu as $order => $top ) {
          $i++;
          if ( 0 == $order ) {
              $menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
              $lastm = 0;
              continue;
          }
          if ( 0 === strpos( $top[2], 'separator' ) && false !== $lastm ) {
              // if separator
              $firstm = true;
              $c = $menu[ $lastm ][4];
              $menu[ $lastm ][4] = add_cssclass( 'menu-top-last', $c );
              continue;
          }
            if ( $first ) {
              $c = $menu[ $order ][4];
              $menu[ $order ][4] = add_cssclass( 'menu-top-first', $c );
              $firstm = false;
          }
            $lastm = $order;
}