-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfront-page.php
More file actions
executable file
·159 lines (137 loc) · 4.13 KB
/
front-page.php
File metadata and controls
executable file
·159 lines (137 loc) · 4.13 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Template Name: Landing
*
* This file adds a front page template to Utility Pro.
*
* @package CDils\UtilityPro
* @link http://www.carriedils.com/utility-pro
* @author Carrie Dils
* @copyright Copyright (c) 2015, Carrie Dils
* @license GPL-2.0+
*/
declare( strict_types = 1 );
namespace CDils\UtilityPro;
add_action( 'genesis_meta', __NAMESPACE__ . '\\homepage_setup' );
/**
* Set up the homepage layout by conditionally loading sections when widgets
* are active.
*
* @since 1.0.0
*/
function homepage_setup() {
$home_sidebars = [
'home_welcome' => \is_active_sidebar( 'utility-home-welcome' ),
'home_gallery_1' => \is_active_sidebar( 'utility-home-gallery-1' ),
'call_to_action' => \is_active_sidebar( 'utility-call-to-action' ),
];
// Return early if no sidebars are active.
if ( ! \in_array( true, $home_sidebars, true ) ) {
return;
}
// Get static home page number.
$page = \get_query_var( 'page' ) ? (int) \get_query_var( 'page' ) : 1;
// Only show home page widgets on page 1.
if ( 1 === $page ) {
// Add home welcome area if "Home Welcome" widget area is active.
if ( $home_sidebars['home_welcome'] ) {
add_action( 'genesis_after_header', __NAMESPACE__ . '\\add_home_welcome' );
}
// Add home gallery area if "Home Gallery 1" widget area is active.
if ( $home_sidebars['home_gallery_1'] ) {
add_action( 'genesis_after_header', __NAMESPACE__ . '\\add_home_gallery' );
}
// Add call to action area if "Call to Action" widget area is active.
if ( $home_sidebars['call_to_action'] ) {
add_action( 'genesis_after_header', __NAMESPACE__ . '\\add_call_to_action' );
}
}
// Filter site title markup to include an h1.
add_filter( 'genesis_site_title_wrap', __NAMESPACE__ . '\\return_h1' );
// Remove standard loop and replace with loop showing latest Posts, not Page content.
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', __NAMESPACE__ . '\\front_loop' );
// Reposition featured image.
add_action( 'genesis_entry_header', 'genesis_do_post_image', 4 );
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
// Reposition post info.
add_action( 'genesis_entry_header', 'genesis_post_info', 8 );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
// Remove unwanted elements.
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
}
/**
* Use h1 for site title on a static front page.
*
* Hat tip to Bill Erickson for the suggestion.
*
* @see http://www.billerickson.net/genesis-h1-front-page/
*
* @since 1.2.0
*/
function return_h1() {
return 'h1';
}
/**
* Display content for the "Home Welcome" section.
*
* @since 1.0.0
*/
function add_home_welcome() {
\genesis_widget_area( 'utility-home-welcome',
[
'before' => '<div class="home-welcome"><div class="wrap">',
'after' => '</div></div>',
]
);
}
/**
* Display content for the "Home Gallery" section.
*
* @since 1.0.0
*/
function add_home_gallery() {
\printf( '<div %s>', \genesis_attr( 'home-gallery' ) );
\genesis_structural_wrap( 'home-gallery' );
foreach ( \range( 1, 4 ) as $widget_area_id ) {
\genesis_widget_area(
'utility-home-gallery-' . $widget_area_id,
[
'before' => '<div class="home-gallery-' . $widget_area_id . ' widget-area">',
'after' => '</div>',
]
);
}
\genesis_structural_wrap( 'home-gallery', 'close' );
echo '</div>';
}
/**
* Display content for the "Call to action" section.
*
* @since 1.0.0
*/
function add_call_to_action() {
\genesis_widget_area(
'utility-call-to-action',
[
'before' => '<div class="call-to-action-bar"><div class="wrap">',
'after' => '</div></div>',
]
);
}
/**
* Display latest posts instead of static page.
*
* @since 1.0.0
*/
function front_loop() {
global $query_args;
\genesis_custom_loop( \wp_parse_args( $query_args, [
'post_type' => 'post',
'paged' => \get_query_var( 'page' ),
] ) );
}
\genesis();