-
Notifications
You must be signed in to change notification settings - Fork 1
/
front-page.php
66 lines (51 loc) · 2.43 KB
/
front-page.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
<?php
namespace LearningCurve;
// Check to see if any of the front-page home widgets are active. If they are then do stuff
// https://developer.wordpress.org/reference/functions/is_active_sidebar/
if ( is_active_sidebar( 'home-top' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-bottom' ) ) {
// Use HTML API to remove the 3/4 width class from the primary content area and replace it with a full width class.
// https://www.getbeans.io/code-reference/functions/beans_replace_attribute/
beans_replace_attribute( 'beans_primary', 'class', 'uk-width-medium-3-4', 'uk-container-center' );
// Use the modify action callback to replace the beans loop with our own callback that displays widgets and sets page layout
// https://www.getbeans.io/documentation/using-actions/
// https://www.getbeans.io/code-reference/functions/beans_modify_action_callback/
beans_modify_action_callback( 'beans_loop_template', NS . '\beansdev_display_home_widget_layout' );
}
/**
* Callback that only runs if home page widgets are active.
* Set page layout to full width
* Display active widgets.
*/
function beansdev_display_home_widget_layout() {
// Add callback on beans layout hook - callback will set full width layout.
add_filter( 'beans_layout', NS . '\set_full_width_layout' );
// Array with the id of each widget created in functions.php
$home_widgets = [ 'home-top', 'home-middle', 'home-bottom' ];
// Use array map to apply render callback to each of the widgets in the array
// https://secure.php.net/manual/en/function.array-map.php
array_map( NS . '\render_home_page_widgets', $home_widgets );
}
/**
* Callback to render the home widget
*
* @param string $home_widget ID of the widget to be rendered.
*/
function render_home_page_widgets( $home_widget ) {
// Check if the widget area is active before doing anything.
// https://developer.wordpress.org/reference/functions/is_active_sidebar/
if ( is_active_sidebar( $home_widget ) ) {
// If the widget is active then load the home page widget view.
// Widget ID is passed to the view and used to generate the class for CSS
include CHILD_THEME_DIR . '/views/home-widgets.php';
}
}
/**
* Set the full width layout
* @return string string required to set the page layout to full width.
*/
function set_full_width_layout() {
// c is the string that tells beans to force a full width layout.
// https://www.getbeans.io/code-snippets/force-a-layout
return 'c';
}
beans_load_document();