|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package bitsy |
|
4
|
|
|
* @author Eric Amundson <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Count number of widgets in a sidebar |
|
9
|
|
|
* Used to add classes to widget areas so widgets can be displayed one, two, three or four per row |
|
10
|
|
|
*/ |
|
11
|
|
|
if ( ! function_exists( 'bitsy_slbd_count_widgets' ) ) { |
|
12
|
|
|
function bitsy_slbd_count_widgets( $sidebar_id ) { |
|
13
|
|
|
// If loading from front page, consult $_wp_sidebars_widgets rather than options |
|
14
|
|
|
// to see if wp_convert_widget_settings() has made manipulations in memory. |
|
15
|
|
|
global $_wp_sidebars_widgets; |
|
16
|
|
|
if ( empty( $_wp_sidebars_widgets ) ) { |
|
17
|
|
|
$_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() ); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
$sidebars_widgets_count = $_wp_sidebars_widgets; |
|
20
|
|
|
|
|
21
|
|
|
if ( isset( $sidebars_widgets_count[ $sidebar_id ] ) ) { |
|
22
|
|
|
$widget_count = count( $sidebars_widgets_count[ $sidebar_id ] ); |
|
23
|
|
|
$widget_classes = 'widget-count-' . count( $sidebars_widgets_count[ $sidebar_id ] ); |
|
24
|
|
|
|
|
25
|
|
|
if ( 0 == $widget_count % 4 || $widget_count > 6 ) { |
|
26
|
|
|
// Four widgets per row if there are exactly four or more than six |
|
27
|
|
|
$widget_classes .= ' col-md-3'; |
|
28
|
|
|
} elseif ( 6 == $widget_count ) { |
|
29
|
|
|
// If two widgets are published |
|
30
|
|
|
$widget_classes .= ' col-md-2'; |
|
31
|
|
|
} elseif ( $widget_count >= 3 ) { |
|
32
|
|
|
// Three widgets per row if there's three or more widgets |
|
33
|
|
|
$widget_classes .= ' col-md-4'; |
|
34
|
|
|
} elseif ( 2 == $widget_count ) { |
|
35
|
|
|
// If two widgets are published |
|
36
|
|
|
$widget_classes .= ' col-md-6'; |
|
37
|
|
|
} elseif ( 1 == $widget_count ) { |
|
38
|
|
|
// If just on widget is active |
|
39
|
|
|
$widget_classes .= ' col-md-12'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $widget_classes; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
/** |
|
47
|
|
|
* Initializes themes widgets. |
|
48
|
|
|
*/ |
|
49
|
|
|
if ( ! function_exists( 'bitsy_widgets_init' ) ) { |
|
50
|
|
|
|
|
51
|
|
|
function bitsy_widgets_init() { |
|
52
|
|
|
register_sidebar( array( |
|
|
|
|
|
|
53
|
|
|
'name' => __( 'Right Sidebar', 'spurs' ), |
|
|
|
|
|
|
54
|
|
|
'id' => 'right-sidebar', |
|
55
|
|
|
'description' => 'Right sidebar widget area', |
|
56
|
|
|
'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|
57
|
|
|
'after_widget' => '</aside>', |
|
58
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
59
|
|
|
'after_title' => '</h3>', |
|
60
|
|
|
) ); |
|
61
|
|
|
|
|
62
|
|
|
register_sidebar( array( |
|
63
|
|
|
'name' => __( 'Left Sidebar', 'spurs' ), |
|
64
|
|
|
'id' => 'left-sidebar', |
|
65
|
|
|
'description' => 'Left sidebar widget area', |
|
66
|
|
|
'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|
67
|
|
|
'after_widget' => '</aside>', |
|
68
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
69
|
|
|
'after_title' => '</h3>', |
|
70
|
|
|
) ); |
|
71
|
|
|
|
|
72
|
|
|
register_sidebar( array( |
|
73
|
|
|
'name' => __( 'Hero Slider', 'spurs' ), |
|
74
|
|
|
'id' => 'hero', |
|
75
|
|
|
'description' => 'Hero slider area. Place two or more widgets here and they will slide!', |
|
76
|
|
|
'before_widget' => '<div class="carousel-item">', |
|
77
|
|
|
'after_widget' => '</div>', |
|
78
|
|
|
'before_title' => '', |
|
79
|
|
|
'after_title' => '', |
|
80
|
|
|
) ); |
|
81
|
|
|
|
|
82
|
|
|
register_sidebar( array( |
|
83
|
|
|
'name' => __( 'Hero Static', 'spurs' ), |
|
84
|
|
|
'id' => 'static-hero', |
|
85
|
|
|
'description' => 'Static Hero widget. no slider functionality', |
|
86
|
|
|
'before_widget' => '<div id="%1$s" class="static-hero-widget %2$s ' . bitsy_slbd_count_widgets( 'static-hero' ) . '">', |
|
87
|
|
|
'after_widget' => '</div><!-- .static-hero-widget -->', |
|
88
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
89
|
|
|
'after_title' => '</h3>', |
|
90
|
|
|
) ); |
|
91
|
|
|
|
|
92
|
|
|
register_sidebar( array( |
|
93
|
|
|
'name' => __( 'Footer Full', 'spurs' ), |
|
94
|
|
|
'id' => 'footer-full', |
|
95
|
|
|
'description' => 'Widget area below main content and above footer', |
|
96
|
|
|
'before_widget' => '<div id="%1$s" class="footer-widget %2$s ' . bitsy_slbd_count_widgets( 'footer-full' ) . '">', |
|
97
|
|
|
'after_widget' => '</div><!-- .footer-widget -->', |
|
98
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
99
|
|
|
'after_title' => '</h3>', |
|
100
|
|
|
) ); |
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
} // endif function_exists( 'bitsy_widgets_init' ). |
|
104
|
|
|
add_action( 'widgets_init', 'bitsy_widgets_init' ); |
|
|
|
|
|