/
functions.php
249 lines (228 loc) · 10.2 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
<?php
/**
* Altadena functions and definitions
*
* Sets up the theme and provides some helper functions, which are used
* in the theme as custom template tags. Others are attached to action and
* filter hooks in WordPress to change core functionality.
*
* When using a child theme (see http://codex.wordpress.org/Theme_Development and
* http://codex.wordpress.org/Child_Themes), you can override certain functions
* (those wrapped in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before the parent
* theme's file, so the child theme functions would be used.
*
* Functions that are not pluggable (not wrapped in function_exists()) are instead attached
* to a filter or action hook.
*
* For more information on hooks, actions, and filters, @link http://codex.wordpress.org/Plugin_API
*
* @package WordPress
* @subpackage Altadena
* @since Altadena 1.0
*/
// ============================================================================
// CUSTOM FUNCTIONS
// ============================================================================
function menu_items() {
$pages = get_pages('sort_column=menu_order');
$Output = "";
foreach ($pages as $page) {
if ($page->post_title !== ''):
$Output .= '<p><a href="' . get_page_link($page->ID) . '">' . $page->post_title . '</a></p>';
endif;
}
echo $Output;
}
function header_text_display() {
// Has the text been hidden?
if (display_header_text() == 1):
return "inline-block";
else:
return "none";
endif;
}
function header_textshadow_settings(){
if (get_theme_mod('display_header_textshadow') == '')://if the box is not checked, do not display text shadow
return "";
else:
return "0 0 4px";
endif;
}
function header_bg_image_settings() {
$header_settings_array = array();
if (get_theme_mod('display_header_img_as_header_bg') == '')://if the box is not checked, display image to the left
$header_settings_array["header_img_display"] = "block";
$header_settings_array["header_img"] = esc_url(get_header_image());
$header_settings_array["header_bg_img"] = "";
$header_settings_array["text_align"] = "left";
$header_settings_array["header_bg_size"] = "";
$header_settings_array["header_bg_repeat"] = "";
$header_settings_array["header_bg_position"] = "";
return $header_settings_array;
else:
$header_settings_array["header_img_display"] = "none";
$header_settings_array["header_img"] = "";
$header_settings_array["header_bg_img"] = esc_url(get_header_image());
$header_settings_array["text_align"] = "center";
$header_settings_array["header_bg_position"] = "center";
switch (get_theme_mod('header_bg_img_style')):
case "repeat":
$header_settings_array["header_bg_size"] = "contain";
$header_settings_array["header_bg_repeat"] = "repeat";
break;
case "stretch":
$header_settings_array["header_bg_size"] = "100%, 100%";
$header_settings_array["header_bg_repeat"] = "no-repeat";
break;
default:
$header_settings_array["header_bg_size"] = "auto, 100%";
$header_settings_array["header_bg_repeat"] = "no-repeat";
endswitch;
return $header_settings_array;
endif;
}
// ============================================================================
// THEME SUPPORT
// ============================================================================
add_theme_support('custom-header', array(
'width' => 190,
'height' => 100,
'default-image' => get_template_directory_uri() . '/images/header.jpg',
'random-default' => false,
'uploads' => true,
'flex-height' => true,
'flex-width' => true,
'default-text-color' => '#333333',
'header-text' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
));
//add_theme_support('title-tag');
add_theme_support('custom-background', array(
'default-color' => '#006666',
'default-image' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
));
// ============================================================================
// THEME CUSTOMIZE REGISTER
// ============================================================================
function altadena_customize_register($wp_customize) {
// =============================
// = Color Picker =
// =============================
$wp_customize->add_setting('altadena_header_textshadow_color', array(
'default' => '#B2C3D3'
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'header_textshadow_color', array(
'label' => __('Header Text Shadow Color', 'altadena'),
'section' => 'colors',
'settings' => 'altadena_header_textshadow_color',
)));
$wp_customize->add_setting('display_header_textshadow');
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'display_header_textshadow', array(
'type' => 'checkbox',
'label' => 'Display Header Text Shadow',
'section' => 'colors',
)));
//--------------------------------------------------------------------------
$wp_customize->add_setting('altadena_header_bg_color', array(
'default' => '#B2C3D3'
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'header_bg_color', array(
'label' => __('Header Background Color', 'altadena'),
'section' => 'colors',
'settings' => 'altadena_header_bg_color',
)));
//--------------------------------------------------------------------------
$wp_customize->add_setting('altadena_content_bg_color', array(
'default' => '#FFFFFF'
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'content_bg_color', array(
'label' => __('Content Background Color', 'altadena'),
'section' => 'colors',
'settings' => 'altadena_content_bg_color',
)));
//--------------------------------------------------------------------------
$wp_customize->add_setting('altadena_text_color', array(
'default' => '#000000'
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'text_color', array(
'label' => __('Text Color', 'altadena'),
'section' => 'colors',
'settings' => 'altadena_text_color',
)));
//--------------------------------------------------------------------------
$wp_customize->add_setting('altadena_nav_color', array(
'default' => '#006666'
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'nav_color', array(
'label' => __('Navigation Color', 'altadena'),
'section' => 'colors',
'settings' => 'altadena_nav_color',
)));
//--------------------------------------------------------------------------
$wp_customize->add_setting('altadena_link_color', array(
'default' => '#0000EE'
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_color', array(
'label' => __('Hyperlink Color', 'altadena'),
'section' => 'colors',
'settings' => 'altadena_link_color',
)));
//--------------------------------------------------------------------------
//
// =============================
// = Check Box =
// =============================
$wp_customize->add_setting('display_header_img_as_header_bg');
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'display_header_img_as_header_bg', array(
'type' => 'checkbox',
'label' => 'Display Header Image as header background',
'section' => 'header_image',
)));
//--------------------------------------------------------------------------
// =============================
// = Radio Button =
// =============================
$wp_customize->add_setting('header_bg_img_style', array('default' => 'no-repeat'));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'header_bg_img_style', array(
'type' => 'radio',
'label' => 'Header background Image style',
'section' => 'header_image',
'choices' => array(
'no-repeat' => 'No Repeat (default)',
'repeat' => 'Repeat',
'stretch' => 'Stretch',
)
)));
}
add_action('customize_register', 'altadena_customize_register');
// ============================================================================
// LIVE CSS SUPPORT
// ============================================================================
function altadena_customizer_css() {
$header_settings = header_bg_image_settings();
?><style type="text/css">
a { color: <?php echo get_theme_mod('altadena_link_color'); ?>; }
body { color: <?php echo get_theme_mod('altadena_text_color'); ?>; }
#header { background-color: <?php echo get_theme_mod('altadena_header_bg_color'); ?>;
text-align: <?php echo $header_settings["text_align"]; ?>;
background-image: url("<?php echo $header_settings["header_bg_img"]; ?>");
background-size: <?php echo $header_settings["header_bg_size"]; ?>;
background-repeat: <?php echo $header_settings["header_bg_repeat"]; ?>;
background-position: <?php echo $header_settings["header_bg_position"]; ?>;
text-shadow: <?php echo header_textshadow_settings(); ?><?php echo get_theme_mod('altadena_header_textshadow_color'); ?>;
}
#header img { display: <?php echo $header_settings["header_img_display"]; ?>; }
#container { background-color: <?php echo get_theme_mod('altadena_content_bg_color'); ?>; }
#nav a { color: <?php echo get_theme_mod('altadena_nav_color'); ?>; }
#nav a:visited { color: <?php echo get_theme_mod('altadena_nav_color'); ?>; }
.site-title, .site-description, .page-title { display: <?php echo header_text_display(); ?>; }
</style>
<?php
}
add_action('wp_head', 'altadena_customizer_css');