-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·546 lines (467 loc) · 18.6 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<?php
/**
* Bootstrap functions and definitions
*
* Sets up the theme and provides some helper functions. Some helper functions
* are used in the theme as custom template tags. Others are attached to action and
* filter hooks in WordPress to change core functionality.
*
*
* @package WordPress
* @subpackage WP-Bootstrap
* @since WP-Bootstrap 0.1
*
* Last Updated: September 9, 2012
*/
if (!defined('BOOTSTRAPWP_VERSION'))
define('BOOTSTRAPWP_VERSION', '.90');
/**
* Declaring the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) )
$content_width = 770; /* pixels */
/**
* Declaring the theme language domain
*/
load_theme_textdomain('bootstrapwp');
/*
| -------------------------------------------------------------------
| Setup Theme
| -------------------------------------------------------------------
|
| */
add_action( 'after_setup_theme', 'bootstrapwp_theme_setup' );
if ( ! function_exists( 'bootstrapwp_theme_setup' ) ):
function bootstrapwp_theme_setup() {
add_theme_support( 'automatic-feed-links' );
/**
* Adds custom menu with wp_page_menu fallback
*/
register_nav_menus( array(
'main-menu' => __( 'Main Menu', 'bootstrapwp' ),
) );
add_theme_support( 'post-formats', array( 'aside', 'image', 'gallery', 'link', 'quote', 'status', 'video', 'audio', 'chat' ) );
}
endif;
################################################################################
// Loading All CSS Stylesheets
################################################################################
function bootstrapwp_css_loader() {
wp_enqueue_style('bootstrapwp', get_template_directory_uri().'/css/bootstrapwp.css', false ,'0.90', 'all' );
wp_enqueue_style('prettify', get_template_directory_uri().'/js/google-code-prettify/prettify.css', false ,'1.0', 'all' );
}
add_action('wp_enqueue_scripts', 'bootstrapwp_css_loader');
################################################################################
// Loading all JS Script Files. Remove any files you are not using!
################################################################################
function bootstrapwp_js_loader() {
wp_enqueue_script('bootstrapjs', get_template_directory_uri().'/js/bootstrap.min.js', array('jquery'),'0.90', true );
wp_enqueue_script('prettifyjs', get_template_directory_uri().'/js/google-code-prettify/prettify.js', array('jquery'),'1.0', true );
wp_enqueue_script('demojs', get_template_directory_uri().'/js/bootstrapwp.demo.js', array('jquery'),'0.90', true );
}
add_action('wp_enqueue_scripts', 'bootstrapwp_js_loader');
/*
| -------------------------------------------------------------------
| Top Navigation Bar Customization
| -------------------------------------------------------------------
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*/
function bootstrapwp_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'bootstrapwp_page_menu_args' );
/**
* Get file 'includes/class-bootstrap_walker_nav_menu.php' with Custom Walker class methods
* */
include 'includes/class-bootstrapwp_walker_nav_menu.php';
/*
| -------------------------------------------------------------------
| Registering Widget Sections
| -------------------------------------------------------------------
| */
function bootstrapwp_widgets_init() {
register_sidebar( array(
'name' => 'Page Sidebar',
'id' => 'sidebar-page',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => "</div>",
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => 'Posts Sidebar',
'id' => 'sidebar-posts',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => "</div>",
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar(array(
'name' => 'Home Left',
'id' => 'home-left',
'description' => 'Left textbox on homepage',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'Home Middle',
'id' => 'home-middle',
'description' => 'Middle textbox on homepage',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'Home Right',
'id' => 'home-right',
'description' => 'Right textbox on homepage',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'Footer Content',
'id' => 'footer-content',
'description' => 'Footer text or acknowledgements',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
add_action( 'init', 'bootstrapwp_widgets_init' );
/*
| -------------------------------------------------------------------
| Adding Post Thumbnails and Image Sizes
| -------------------------------------------------------------------
| */
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 160, 120 ); // 160 pixels wide by 120 pixels high
}
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'bootstrap-small', 260, 180 ); // 260 pixels wide by 180 pixels high
add_image_size( 'bootstrap-medium', 360, 268 ); // 360 pixels wide by 268 pixels high
}
/*
| -------------------------------------------------------------------
| Revising Default Excerpt
| -------------------------------------------------------------------
| Adding filter to post excerpts to contain ...Continue Reading link
| */
function bootstrapwp_excerpt($more) {
global $post;
return ' <a href="'. get_permalink($post->ID) . '" class="continue-reading">...Continue Reading</a>';/*added class to style continue reading buttone*/
}
add_filter('excerpt_more', 'bootstrapwp_excerpt');
if ( ! function_exists( 'bootstrapwp_content_nav' ) ):
/**
* Display navigation to next/previous pages when applicable
*/
function bootstrapwp_content_nav( $nav_id ) {
global $wp_query;
?>
<?php if ( is_single() ) : // navigation links for single posts ?>
<ul class="pager">
<?php previous_post_link( '<li class="previous">%link</li>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'bootstrapwp' ) . '</span> %title' ); ?>
<?php next_post_link( '<li class="next">%link</li>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'bootstrapwp' ) . '</span>' ); ?>
</ul>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<ul class="pager">
<?php if ( get_next_posts_link() ) : ?>
<li class="next"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'bootstrapwp' ) ); ?></li>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<li class="previous"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'bootstrapwp' ) ); ?></li>
<?php endif; ?>
</ul>
<?php endif; ?>
<?php
}
endif; // bootstrapwp_content_nav
if ( ! function_exists( 'bootstrapwp_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own bootstrap_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since WP-Bootstrap .5
*/
function bootstrapwp_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'bootstrap' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'bootstrap' ), ' ' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<footer>
<div class="comment-author vcard">
<?php echo get_avatar( $comment, 40 ); ?>
<?php printf( __( '%s <span class="says">says:</span>', 'bootstrap' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em><?php _e( 'Your comment is awaiting moderation.', 'bootstrap' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><time pubdate datetime="<?php comment_time( 'c' ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'bootstrap' ), get_comment_date(), get_comment_time() ); ?>
</time></a>
<?php edit_comment_link( __( '(Edit)', 'bootstrap' ), ' ' );
?>
</div><!-- .comment-meta .commentmetadata -->
</footer>
<div class="comment-content"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // ends check for bootstrapwp_comment()
if ( ! function_exists( 'bootstrapwp_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
* Create your own bootstrap_posted_on to override in a child theme
*
* @since WP-Bootstrap .5
*/
function bootstrapwp_posted_on() {
printf( __( '<span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span><span class="sep"> - </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="byline"> - ', 'bootstrap' ),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'bootstrap' ), get_the_author() ) ),
esc_html( get_the_author() )
);
}
endif;
/**
* Adds custom classes to the array of body classes.
*
* @since WP-Bootstrap .5
*/
function bootstrapwp_body_classes( $classes ) {
// Adds a class of single-author to blogs with only 1 published author
if ( ! is_multi_author() ) {
$classes[] = 'single-author';
}
return $classes;
}
add_filter( 'body_class', 'bootstrapwp_body_classes' );
/**
* Returns true if a blog has more than 1 category
*
* @since WP-Bootstrap .5
*/
function bootstrapwp_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
// This blog has more than 1 category so bootstrap_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so bootstrap_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in bootstrapwp_categorized_blog
*
* @since bootstrap 1.2
*/
function bootstrapwp_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'bootstrapwp_category_transient_flusher' );
add_action( 'save_post', 'bootstrapwp_category_transient_flusher' );
/**
* Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
*/
function bootstrapwp_enhanced_image_navigation( $url ) {
global $post;
if ( wp_attachment_is_image( $post->ID ) )
$url = $url . '#main';
return $url;
}
add_filter( 'attachment_link', 'bootstrapwp_enhanced_image_navigation' );
/*
| -------------------------------------------------------------------
| Checking for Post Thumbnail
| -------------------------------------------------------------------
|
| */
function bootstrapwp_post_thumbnail_check() {
global $post;
if (get_the_post_thumbnail()) {
return true; }
else { return false; }
}
/*
| -------------------------------------------------------------------
| Setting Featured Image (Post Thumbnail)
| -------------------------------------------------------------------
| Will automatically add the first image attached to a post as the Featured Image if post does not have a featured image previously set.
| */
function bootstrapwp_autoset_featured_img() {
$post_thumbnail = bootstrapwp_post_thumbnail_check();
if ($post_thumbnail == true ){
return the_post_thumbnail();
}
if ($post_thumbnail == false ){
$image_args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'order' => 'desc'
);
$attached_image = get_children( $image_args );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
return the_post_thumbnail();
} else { return " ";}
}
} //end function
/*
| -------------------------------------------------------------------
| Adding Breadcrumbs
| -------------------------------------------------------------------
|
| */
function bootstrapwp_breadcrumbs() {
$delimiter = '<span class="divider">/</span>';
$home = 'Home'; // text for the 'Home' link
$before = '<li class="active">'; // tag before the current crumb
$after = '</li>'; // tag after the current crumb
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<ul class="breadcrumb">';
global $post;
$homeLink = home_url();
echo '<li><a href="' . $homeLink . '">' . $home . '</a></li> ' . $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
} elseif ( is_day() ) {
echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></li> ' . $delimiter . ' ';
echo '<li><a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a></li> ' . $delimiter . ' ';
echo $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></li> ' . $delimiter . ' ';
echo $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo '<li><a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a></li> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<li><a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a></li> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_search() ) {
echo $before . 'Search results for "' . get_search_query() . '"' . $after;
} elseif ( is_tag() ) {
echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $before . 'Articles posted by ' . $userdata->display_name . $after;
} elseif ( is_404() ) {
echo $before . 'Error 404' . $after;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page', 'bootstrapwp') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '</ul>';
}
} // end bootstrapwp_breadcrumbs()
/**
* This theme was built with PHP, Semantic HTML, CSS, love, and a bootstrap.
*/
add_action('init', 'faq_init');
function faq_init() {
$args = array(
'labels' => array(
'name' => __('faqs'),
'singular_name' => __('faq'),
),
'public' => true,
);
register_post_type( 'faq' , $args );
}
add_action('init', 'services_init');
function services_init() {
$args = array(
'labels' => array(
'name' => __('services'),
'singular_name'=>__('service'),
),
'public' => true,
);
register_post_type('services',$args);
}