-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
277 lines (244 loc) · 9.72 KB
/
functions.php
File metadata and controls
277 lines (244 loc) · 9.72 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
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
<?php
/**
* Functions and definitions
*
* This file contains functions that are required to this theme. Some functions can be overriden in a child-theme
* while others are not.
*/
/**
* Setup menus and various supports.
*/
function codeandbeauty_setup() {
// Let WP set the page's <title> tag
add_theme_support( 'title-tag' );
// This theme's uses custom logo
$custom_logo_args = array(
'height' => 160,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
);
add_theme_support( 'custom-logo', $custom_logo_args );
// Add image sizes
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
add_image_size( 'full-feature', 1024, 400, true );
add_image_size( 'full-feature-2', 1600, 600, true );
add_image_size( 'feature-image', 572, 372, true );
// This theme uses 3 menu locations
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'TEXTDOMAIN' ),
'main' => __( 'Main Navigation', 'TEXTDOMAIN' ),
'footer-links' => __( 'Footer Links', 'TEXTDOMAIN' ),
) );
// Enable background support
add_theme_support( 'custom-background' );
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
}
add_action( 'after_setup_theme', 'codeandbeauty_setup' );
function codeandbeauty_widgets_init() {
$sidebar_args = array(
'before_widget' => '<aside id="%1$s" class="widget %2$s"><div class="inner-widget">',
'after_widget' => '</div></aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
);
// Header Box
register_sidebar( wp_parse_args( array(
'id' => 'header-box',
'name' => __( 'Header Box', 'TEXTDOMAIN' ),
'description' => __( 'Visible at the top-right corner of your page.', 'TEXTDOMAIN' ),
), $sidebar_args ) );
// Left Sidebar
register_sidebar( wp_parse_args( array(
'id' => 'left-sidebar',
'name' => __( 'Left Sidebar', 'TEXTDOMAIN' ),
'description' => __( 'Visible at the left side corner of your page.', 'TEXTDOMAIN' ),
), $sidebar_args ) );
// Right sidebar
register_sidebar( wp_parse_args( array(
'id' => 'right-sidebar',
'name' => __( 'Right Sidebar', 'TEXTDOMAIN' ),
'description' => __( 'Visible at the right side corner of your page.', 'TEXTDOMAIN' ),
), $sidebar_args ) );
// Footer Widgets
register_sidebar( wp_parse_args( array(
'id' => 'footer-widgets',
'name' => __( 'Footer Widgets', 'TEXTDOMAIN' ),
'description' => __( 'Visible at the bottom of your page.', 'TEXTDOMAIN' ),
), $sidebar_args ) );
}
add_action( 'widgets_init', 'codeandbeauty_widgets_init' );
if ( ! function_exists( 'codeandbeauty_customizer' ) ) :
/**
* Custom customizer options are optional but are commonly practice in most theme.
* Here are some minimal customizer options that you can either remove or extend
* at your disposal.
*
* @param $customizer
*/
function codeandbeauty_customizer( $customizer ) {
/**
* Our top section header use mini logo. Let's add an option to allow
* uploading a mini logo at `Site Identity` section.
*/
$customizer->add_setting( 'mini_logo' );
$control_args = array(
'label' => __( 'Mini Logo', 'TEXTDOMAIN' ),
'section' => 'title_tagline',
);
$customizer->add_control( new WP_Customize_Image_Control( $customizer, 'mini_logo', $control_args ) );
/**
* Let's create a new section that will hold all other site informations
* needed in our theme.
*/
$customizer->add_section( 'site_info', array(
'title' => __( 'Site Info', 'TEXTDOMAIN' ),
));
/**
* Another feature our top section have is a custom text, this could be a plain text or
* a shortcode.
*/
$customizer->add_setting( 'top_text' );
$control_args = array(
'label' => __( 'Top Text', 'TEXTDOMAIN' ),
'description' => __( 'Add a single line text or shortcode that will be visible at the top-left corner of your page.', 'TEXTDOMAIN' ),
'section' => 'site_info',
'type' => 'textarea',
'sanitize_callback' => 'sanitize_textarea',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'top_text', $control_args ) );
// Social media
$social_medias = array(
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'linkedin' => 'LinkedIn',
'google-plus' => 'Google+',
'rss' => 'RSS',
'email' => 'Email',
);
foreach ( $social_medias as $social => $label ) {
$name = 'social_media[' . $social . ']';
$customizer->add_setting( $name );
$control_args = array(
'description' => $label,
'section' => 'site_info',
);
if ( 'facebook' == $social ) {
$control_args['label'] = __( 'Social Media Links', 'TEXTDOMAIN' );
}
$customizer->add_control( new WP_Customize_Control( $customizer, $name, $control_args ) );
}
/**
* The bottom most part of our footer use footer text. Let's add an box area option
* for our footer text.
*/
$customizer->add_setting( 'footer_text' );
$control_args = array(
'label' => __( 'Footer/Copyright Text', 'TEXTDOMAIN' ),
'description' => __( 'Write your site\'s copyright or any useful text that will be visible at the bottom most part of the page.', 'TEXTDOMAIN' ),
'type' => 'textarea',
'sanitize_callback' => 'sanitize_textarea',
'section' => 'site_info',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'footer_text', $control_args ) );
$customizer->add_panel( 'home-page', array(
'title' => __( 'Homepage', 'TEXTDOMAIN' ),
'description' => __( 'A custom homepage template.', 'TEXTDOMAIN' ),
) );
// Featured page
$customizer->add_section( 'featured_page', array(
'title' => __( 'Featured Page', 'TEXTDOMAIN' ),
'panel' => 'home-page',
) );
$customizer->add_setting( 'featured_page[page_id]' );
$control_args = array(
'label' => __( 'Select page', 'TEXTDOMAIN' ),
'type' => 'dropdown-pages',
'section' => 'featured_page',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_page[page_id]', $control_args ) );
$customizer->add_setting( 'featured_page[read_more]' );
$control_args = array(
'label' => __( 'Read More Label', 'TEXTDOMAIN' ),
'section' => 'featured_page',
'input_attrs' => array(
'placeholder' => __( 'Continue reading...', 'TEXTDOMAIN' ),
),
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_page[read_more]', $control_args ) );
// Featured Contents
$customizer->add_section( 'featured_contents', array(
'title' => __( 'Featured Contents', 'TEXTDOMAIN' ),
'panel' => 'home-page',
) );
$customizer->add_setting( 'featured_contents[heading]' );
$control_args = array(
'label' => __( 'Heading', 'TEXTDOMAIN' ),
'sanitize_callback' => 'sanitize_textfield',
'section' => 'featured_contents',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[heading]', $control_args ) );
$customizer->add_setting( 'featured_contents[description]' );
$control_args = array(
'label' => __( 'Description', 'TEXTDOMAIN' ),
'type' => 'textarea',
'sanitize_callback' => 'sanitize_textarea',
'section' => 'featured_contents',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[description]', $control_args ) );
$post_types = get_post_types( array( 'public' => true ), 'objects' );
if ( $post_types ) {
foreach ( $post_types as $post_type => $object ) {
$post_types[ $post_type ] = $object->label;
}
}
unset( $post_types['page'], $post_types['attachment'] );
$customizer->add_setting( 'featured_contents[post_type]' );
$control_args = array(
'label' => __( 'Content type', 'TEXTDOMAIN' ),
'type' => 'select',
'section' => 'featured_contents',
'choices' => $post_types,
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[post_type]', $control_args ) );
$customizer->add_setting( 'featured_contents[tax]' );
$control_args = array(
'label' => __( 'Category, Tags, or custom Taxonomy', 'TEXTDOMAIN' ),
'description' => __( 'Separate each with comma. (i.e. Apple, Orange)', 'TEXTDOMAIN' ),
'section' => 'featured_contents',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[tax]', $control_args ) );
$customizer->add_setting( 'featured_contents[posts_per_page]' );
$control_args = array(
'label' => __( 'Number of items', 'TEXTDOMAIN' ),
'sanitize_callback' => 'intval',
'section' => 'featured_contents',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[posts_per_page]', $control_args ) );
$customizer->add_setting( 'featured_contents[view_more]' );
$control_args = array(
'label' => __( 'View More label', 'TEXTDOMAIN' ),
'sanitize_callback' => 'sanitize_textfield',
'section' => 'featured_contents',
'input_attrs' => array(
'placeholder' => __( 'View More', 'TEXTDOMAIN' ),
),
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[view_more]', $control_args ) );
$customizer->add_setting( 'featured_contents[view_more_link]' );
$control_args = array(
'label' => __( 'View More Url', 'TEXTDOMAIN' ),
'sanitize_callback' => 'sanitize_textfield',
'section' => 'featured_contents',
);
$customizer->add_control( new WP_Customize_Control( $customizer, 'featured_contents[view_more_link]', $control_args ) );
}
add_action( 'customize_register', 'codeandbeauty_customizer' );
endif;
// Include template-tags
get_template_part( 'inc/template-tags' );