-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
359 lines (310 loc) · 11.7 KB
/
functions.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?php
/**
* Muis - functions
*
* @package Muis
*/
/*if( !isset( $content_width ) )
$content_width =1000;*/
if( !function_exists( 'muis_setup' ) ) :
/**
* General Wordpress theme setup
*/
function muis_setup() {
/*
* Make theme available for translation.
*/
load_theme_textdomain( 'muis' );
/*
* Let WordPress manage the document title.
*/
add_theme_support( 'title-tag' );
/* Thumbnail support */
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1280, 1280 );
/* Set-up menus */
register_nav_menus( array(
'primary' => __( 'Top Right', 'muis' ),
'secondary' => __( 'Top Left', 'muis' ) ) );
/**
* Enable support for the following post formats:
* aside, gallery, quote, image, and video
*/
add_theme_support( 'post-formats', array ( 'aside', 'gallery', 'quote', 'image', 'video' ) );
/**
* Enable custom header in the customizer
*/
add_theme_support( 'custom-header', apply_filters( 'muis_custom_header_args', array(
'default-image' => get_parent_theme_file_uri( '/images/header.jpg' ),
'width' => 1600,
'height' => 900,
'flex-height' => true,
'video' => false,
'header-text' => true,
'wp-head-callback' => 'muis_header_style',
) ) );
register_default_headers( array(
'default-image' => array(
'url' => '%s/images/header.jpg',
'thumbnail_url' => '%s/images/header.jpg',
'description' => __( 'Default Header Image', 'muis' ),
),
) );
// Add theme support for Custom Logo.
add_theme_support( 'custom-logo', array(
'width' => 250,
'height' => 250,
'flex-width' => true,
) );
}
add_action( 'after_setup_theme', 'muis_setup' );
endif;
if( !function_exists( 'muis_scripts' ) ) :
/**
* Configures scripts and stylesheets
*/
function muis_scripts() {
/** Enable the core javascript file */
wp_enqueue_script( 'muis-functions', get_template_directory_uri() . '/js/functions.js', array ( 'jquery' ), '1.0', true );
wp_enqueue_style( 'muis-style', get_stylesheet_uri() );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'muis-ie8', get_theme_file_uri( 'ie8.css' ), array( 'muis-style' ), '1.0' );
wp_style_add_data( 'muis-ie8', 'conditional', 'lt IE 9' );
}
add_action( 'wp_enqueue_scripts', 'muis_scripts' );
endif;
if( !function_exists( 'muis_widgets_init' ) ) :
/**
* Registers widget locations
*/
function muis_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'muis' ),
'id' => 'sidebar',
'before_widget' => '<aside id="%1$s" class="sidebar-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
register_sidebar( array(
'name' => __( 'Full Width Header', 'muis' ),
'id' => 'fw-header',
'before_widget' => '<div id="%1$s" class="fw-header %2$s">',
'after_widget' => '</div>',
'before_title' => '<h1 class="fw-header-tile">',
'after_title' => '</h1>'
) );
register_sidebar( array(
'name' => __( 'Footer One', 'muis' ),
'id' => 'footer-1',
'before_widget' => '<aside id="%1$s" class="sidebar-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
register_sidebar( array(
'name' => __( 'Footer Two', 'muis' ),
'id' => 'footer-2',
'before_widget' => '<aside id="%1$s" class="sidebar-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
register_sidebar( array(
'name' => __( 'Footer Three', 'muis' ),
'id' => 'footer-3',
'before_widget' => '<aside id="%1$s" class="sidebar-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
register_sidebar( array(
'name' => __( 'Footer Four', 'muis' ),
'id' => 'footer-4',
'before_widget' => '<aside id="%1$s" class="sidebar-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
}
add_action( 'widgets_init', 'muis_widgets_init' );
endif;
if (!function_exists('muis_paging_nav')):
/**
* Display navigation to next/previous set of posts when applicable.
*/
function muis_paging_nav() {
// Don't print empty markup if there's only one page.
if ($GLOBALS['wp_query']->max_num_pages < 2) {
return;
}
?>
<nav class="navigation paging-navigation" role="navigation">
<?php next_posts_link(); ?>
</nav>
<?php
}
endif;
if (!function_exists('muis_post_nav')):
/**
* Display navigation to next/previous post when applicable.
*/
function muis_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = (is_attachment()) ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true);
$next = get_adjacent_post(false, '', false);
if (!$next && !$previous) {
return;
}
?>
<nav class="navigation post-navigation fluid-outer" role="navigation">
<h1 class="screen-reader-text"><?php _e('Post navigation', 'muis'); ?></h1>
<div class="nav-links fluid-inner">
<?php
if (is_attachment()):
previous_post_link('%link', __('<span class="meta-nav"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> %title</span>', 'muis'));
else:
next_post_link('%link', __('<span class="meta-nav">%title <i class="fa fa-long-arrow-right" aria-hidden="true"></i></span>', 'muis'));
previous_post_link('%link', __('<span class="meta-nav"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> %title</span>', 'muis'));
endif;
?>
</div>
<!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
endif;
if( !function_exists( 'more_posts' ) ) :
function more_posts() {
global $wp_query;
return $wp_query->current_post + 1 < $wp_query->post_count;
}
endif;
if ( ! function_exists( 'muis_header_style' ) ) :
/**
* Styles the header image and text displayed on the blog.
* This function was kindly borrowed from the `twentyseventeen` theme
*/
function muis_header_style() {
$header_text_color = get_header_textcolor();
$header_text_bgcolor = get_theme_mod( 'header_text_bgcolor', 'blank' );
// If no custom options for text are set, let's bail.
// get_header_textcolor() options: add_theme_support( 'custom-header' ) is default, hide text (returns 'blank') or any hex value.
if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
return;
}
// If we get this far, we have custom styles. Let's do this.
?>
<style id="muis-custom-header-styles" type="text/css">
<?php
// Has the text been hidden?
if ( 'blank' === $header_text_color ) :
?>
.header-text {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
}
<?php
// If the user has set a custom color for the text use that.
else :
?>
.header-text h1 {
color: #<?php echo esc_attr( $header_text_color ); ?> !important;
}
<?php endif;
if( 'blank' === $header_text_bgcolor ) :
?>
.header-text h1 { background-color: transparent !important; }
<?php else: ?>
.header-text h1 {
background-color: <?php echo esc_attr( $header_text_bgcolor ); ?> !important;
}
<?php endif; ?>
</style>
<?php
}
endif;
if( !function_exists( 'muis_pre_get_posts' ) ) {
/**
* This function is executed before The Loop and adapts the WP Query object
* to only show the post categories specified in theme mod 'frontpage_categories'
*/
function muis_pre_get_posts( &$query ) {
if( !$query->is_home() || !$query->is_main_query() )
return true;
$categories =get_theme_mod( 'frontpage_categories', '' );
if( empty( $categories ) )
return true;
/* Modify query to only show specified categories */
$query->query_vars['category_name'] = $categories;
//return true;
}
add_action( 'pre_get_posts', 'muis_pre_get_posts' );
}
if( !function_exists( 'muis_customize_register' ) ) :
/**
* Registers theme modification settings and controls for the customizer.
* TODO: Move to a separate file
*/
function muis_customize_register( $wp_customize ) {
/* Settings */
$wp_customize->add_setting( 'header_text_h1', array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'default' => 'Hello, world!',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => 'esc_html',
'sanitize_js_callback' => '', // Basically to_json.
) );
$wp_customize->add_setting( 'header_text_bgcolor', array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'default' => 'blank',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '', // Basically to_json.
) );
$wp_customize->add_setting( 'frontpage_categories', array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'default' => 'esc_html',
'transport' => 'refresh', // or postMessage
) );
/* Custom sections */
$wp_customize->add_section( 'header_text', array(
'title' => __( 'Header Text', 'muis' ),
'description' => __( 'Edit the text displayed in the frontpage header, if no widget is present', 'muis' ),
'priority' => 160,
'capability' => 'edit_theme_options'
) );
$wp_customize->add_section( 'frontpage_categories', array(
'title' => __( 'Frontpage Categories', 'muis' ),
'description' => __( 'Alters the posts query such that on the frontpage, only posts are shown that are in one of the given categories. Shows all posts if left empty', 'muis' ),
'priority' => 170,
'capability' => 'edit_theme_options'
) );
/* Custom controls */
$wp_customize->add_control( 'header_text_h1', array(
'label' => __( 'Big head', 'muis' ),
'type' => 'textarea',
'section' => 'header_text',
) );
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize, // WP_Customize_Manager
'header_text_bgcolor', // Setting id
array( // Args, including any custom ones.
'label' => __( 'Header Text Background Color', 'muis' ),
'section' => 'colors',
)
)
);
$wp_customize->add_control( 'frontpage_categories', array(
'label' => __( 'List of category slugs, separated by commas', 'muis' ),
'type' => 'textarea',
'section' => 'frontpage_categories',
) );
}
add_action( 'customize_register', 'muis_customize_register' );
endif;
?>