-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar-footer.php
80 lines (72 loc) · 1.77 KB
/
sidebar-footer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* The footer widget area
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package Newspaper X
*/
/**
* The defined sidebars
*/
$mysidebars = array(
'footer-1',
'footer-2',
'footer-3',
'footer-4'
);
/**
* We create an empty array that will keep which one of them has any active sidebars
*/
$sidebars = array();
foreach ( $mysidebars as $column ) {
if ( is_active_sidebar( $column ) ) {
$sidebars[] = $column;
}
};
/**
* Handle the sizing of the footer columns based on the user selection
*/
$count = (int) get_theme_mod( 'newspaper_x_footer_columns', 4 );
/**
* Size can be set dynamically as well by counting the array elements
* $size = 12 / count($sidebars);
*/
$size = 12 / $count;
if ( empty( $sidebars ) ) {
$args = array(
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
);
$widgets = array( 'WP_Widget_Meta', 'WP_Widget_Recent_Posts', 'WP_Widget_Tag_Cloud', 'WP_Widget_Categories' );
$widgets = array_slice( $widgets, 0, $count );
?>
<div class="widgets-area">
<div class="container">
<div class="row">
<?php foreach ( $widgets as $widget ) { ?>
<div class="col-md-<?php echo absint( $size ) ?> col-sm-6">
<?php the_widget( $widget, array(), $args ); ?>
</div>
<?php } ?>
</div>
</div>
</div>
<?php return false;
}
/**
* In case all the sidebars have widgets attached, we slice the array it.
*/
$sidebars = array_slice( $sidebars, 0, $count );
?>
<div class="widgets-area">
<div class="container">
<div class="row">
<?php foreach ( $sidebars as $sidebar ): ?>
<div class="col-md-<?php echo absint( $size ) ?> col-sm-6">
<?php dynamic_sidebar( $sidebar ); ?>
</div>
<?php endforeach; ?>
</div><!--.row-->
</div>
</div>