-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
772 lines (646 loc) · 24.4 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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<?php
/**
* The template functions and definitions
*
* @package WordPress
* @subpackage BirdFILED
* @since BirdFILED 1.0
*/
//////////////////////////////////////////
// Set the content width based on the theme's design and stylesheet.
function birdfield_content_width() {
$GLOBALS['content_width'] = apply_filters( 'birdfield_content_width', 930 );
}
add_action( 'template_redirect', 'birdfield_content_width' );
//////////////////////////////////////////
// Customizer additions.
require get_template_directory() . '/functions_customizer.php';
//////////////////////////////////////////
// Set Widgets
function birdfield_widgets_init() {
register_sidebar( array (
'name' => __( 'Widget Area for header', 'birdfield' ),
'id' => 'widget-area-header',
'description' => __( 'One text widget for header', 'birdfield' ),
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array (
'name' => __( 'Widget Area for footer', 'birdfield' ),
'id' => 'widget-area-footer',
'description' => __( 'Widget Area for footer', 'birdfield' ),
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'birdfield_widgets_init' );
//////////////////////////////////////////////////////
// Header markup
function birdfield_wrapper_class() {
$has_header = false;
$birdfield_class = 'wrapper';
if ( 'blank' == get_header_textcolor()) {
$birdfield_class .= ' no-title';
}
else{
$has_header = true;
}
if ( !has_nav_menu( 'primary' )) {
$birdfield_class .= ' no-nav-menu';
}
else{
$has_header = true;
}
if( $has_header ){
$birdfield_class .= ' fixed-header';
}
echo 'class="' .$birdfield_class .'"';
}
//////////////////////////////////////////////////////
// Copyright Year
function birdfield_get_copyright_year() {
$birdfield_copyright_year = date("Y");
$birdfield_first_year = $birdfield_copyright_year;
$args = array(
'numberposts' => 1,
'orderby' => 'post_date',
'order' => 'ASC',
);
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$birdfield_first_year = mysql2date( 'Y', $post->post_date, true );
}
if( $birdfield_copyright_year <> $birdfield_first_year ){
$birdfield_copyright_year = $birdfield_first_year .' - ' .$birdfield_copyright_year;
}
return $birdfield_copyright_year;
}
//////////////////////////////////////////////////////
// Setup Theme
if ( ! function_exists( 'birdfield_setup' ) ) :
function birdfield_setup() {
// Set languages
load_theme_textdomain( 'birdfield', get_template_directory() . '/languages' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// This theme styles the visual editor with editor-style.css to match the theme style.
add_theme_support( 'editor-styles' );
add_editor_style( 'editor-style.css' );
// Set feed
add_theme_support( 'automatic-feed-links' );
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* This theme supports all available post formats by default.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'
) );
/*
* This theme supports custom background color and image, and here
* we also set up the default background color.
*/
add_theme_support( 'custom-background', array(
'default-image' => '',
'default-color' => 'FFF',
'wp-head-callback' => 'birdfield_custom_background_cb',
) );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Navigation Menu', 'birdfield' ),
) );
// Add support for title tag.
add_theme_support( 'title-tag' );
// Add support for custom headers.
$custom_header_support = array(
'default-image' => '%s/images/header.jpg',
'height' => 900,
'width' => 1280,
'flex-width' => false,
'random-default' => true,
);
// Add support for custom headers.
add_theme_support( 'custom-header', $custom_header_support );
register_default_headers( array(
'birdfield' => array(
'url' => '%s/images/header.jpg',
'thumbnail_url' => '%s/images/header-thumbnail.jpg',
'description' => 'birdfield'
)
) );
// Add support for news content.
add_theme_support( 'news-content', array(
'news_content_filter' => 'birdfield_get_news_posts',
'max_posts' => 5,
) );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
}
endif; // birdfield_setup
add_action( 'after_setup_theme', 'birdfield_setup' );
//////////////////////////////////////////////////////
// Filter the news posts to return
function birdfield_get_news_posts(){
$array = get_posts(array(
'tag_slug__in' => 'news',
'numberposts' => 5
));
return $array;
}
add_filter( 'birdfield_get_news_posts', 'birdfield_get_news_posts', 100 );
//////////////////////////////////////////////////////
// Filter home and the news posts that returns a boolean value.
function birdfield_has_news_posts() {
return ! is_paged() && ( bool ) birdfield_get_news_posts();
}
//////////////////////////////////////////////////////
// Filter main query at home
function birdfield_home_query( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$birdfield_news = get_term_by( 'name', 'news', 'post_tag' );
if( $birdfield_news ){
$query->set( 'tag__not_in', $birdfield_news->term_id );
}
}
}
add_action( 'pre_get_posts', 'birdfield_home_query' );
//////////////////////////////////////////////////////
// Enqueue Scripts
function birdfield_scripts() {
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_enqueue_script( 'birdfield', get_template_directory_uri() .'/js/birdfield.js', array( 'jquery' , 'jquery-masonry' ), '1.13' );
wp_enqueue_style( 'birdfield-google-font', '//fonts.googleapis.com/css?family=Raleway', false, null, 'all' );
wp_enqueue_style( 'birdfield', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'birdfield_scripts' );
//////////////////////////////////////////////////////
// Enqueue Scripts for Dashboard
function birdfield_admin_enqueue_scripts() {
wp_enqueue_style( 'birdfield-google-font', '//fonts.googleapis.com/css?family=Raleway', false, null, 'all' );
}
add_action( 'admin_enqueue_scripts', 'birdfield_admin_enqueue_scripts' );
//////////////////////////////////////////////////////
// Theme Customizer
function birdfield_customize( $wp_customize ) {
// defaut colors
$birdfield_default_colors = birdfield_get_default_colors();
// Text Color
$wp_customize->add_setting( 'birdfield_text_color',
array(
'default' => '#222327',
'sanitize_callback' => 'maybe_hash_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'birdfield_text_color',
array(
'label' => __( 'Text Color', 'birdfield' ),
'section' => 'colors',
'settings' => 'birdfield_text_color',
)));
// Link Color
$wp_customize->add_setting( 'birdfield_link_color',
array(
'default' => '#1c4bbe',
'sanitize_callback' => 'maybe_hash_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'birdfield_link_color',
array(
'label' => __( 'Link Color', 'birdfield' ),
'section' => 'colors',
'settings' => 'birdfield_link_color',
)));
// Header, Footer Background Color
$wp_customize->add_setting( 'birdfield_header_color',
array(
'default' => '#79a596',
'sanitize_callback' => 'maybe_hash_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'birdfield_header_color',
array(
'label' => __( 'Header, Footer Background Color', 'birdfield' ),
'section' => 'colors',
'settings' => 'birdfield_header_color',
)));
// Footer Section
$wp_customize->add_section( 'birdfield_customize',
array(
'title' => __( 'Footer', 'birdfield' ),
'priority' => 62,
));
// Display Copyright
$wp_customize->add_setting( 'birdfield_copyright',
array(
'default' => true,
'sanitize_callback' => 'birdfield_sanitize_checkbox',
));
$wp_customize->add_control( 'birdfield_copyright',
array(
'label' => __( 'Display Copyright', 'birdfield' ),
'section' => 'birdfield_customize',
'type' => 'checkbox',
'settings' => 'birdfield_copyright',
));
// Display Credit
$wp_customize->add_setting( 'birdfield_credit',
array(
'default' => true,
'sanitize_callback' => 'birdfield_sanitize_checkbox',
));
$wp_customize->add_control( 'birdfield_credit',
array(
'label' => __( 'Display Credit', 'birdfield' ),
'section' => 'birdfield_customize',
'type' => 'checkbox',
'settings' => 'birdfield_credit',
));
}
add_action( 'customize_register', 'birdfield_customize' );
//////////////////////////////////////////////////////
// Santize a checkbox
function birdfield_sanitize_checkbox( $input ) {
if ( $input == true ) {
return true;
} else {
return false;
}
}
///////////////////////////////////////////////////////
// Sanitize text
function birdfield_sanitize_text( $input ) {
return wp_kses_post( force_balance_tags( $input ) );
}
//////////////////////////////////////////////////////
// Get default colors
function birdfield_get_default_colors() {
return array( 'header_text_color' => '#ffffff',
'header_color' => '#79a596',
'text_color' => '#222327',
'link_color' => '#1c4bbe' );
}
//////////////////////////////////////////////////////
// Enqueues front-end CSS for the Theme Customizer.
function birdfield_color_css() {
// default color
$birdfield_default_colors = birdfield_get_default_colors();
// Custom Header Text Color
$birdfield_header_text_color = get_header_textcolor();
if( !empty( $birdfield_header_text_color ) && strcasecmp( $birdfield_header_text_color, trim( $birdfield_default_colors[ 'header_text_color' ], '#' ))) {
$birdfield_css = "
/* Custom Header Text Color */
#header #branding #site-title,
#header #branding #site-title a,
#header #branding #site-description,
#menu-wrapper .menu ul#menu-primary-items li a,
#menu-wrapper .menu #small-menu,
#widget-area .widget,
#footer,
#footer a {
color: #{$birdfield_header_text_color};
}
#menu-wrapper .menu ul#menu-primary-items li a {
border-color: #{$birdfield_header_text_color};
}
#menu-wrapper .menu #small-menu .icon,
#menu-wrapper .menu #small-menu .icon:before,
#menu-wrapper .menu #small-menu .icon:after {
background-color: #{$birdfield_header_text_color};
}
@media screen and (min-width: 930px) {
#menu-wrapper .menu ul#menu-primary-items li a:hover {
background-color: #{$birdfield_header_text_color};
}
#menu-wrapper .menu ul#menu-primary-items li ul li a,
#menu-wrapper .menu ul#menu-primary-items li ul li:first-child a {
border-color: #{$birdfield_header_text_color};
}
}
";
wp_add_inline_style( 'birdfield', $birdfield_css );
}
// Custom Text Color
$birdfield_text_color = get_theme_mod( 'birdfield_text_color', $birdfield_default_colors[ 'text_color' ] );
if( strcasecmp( $birdfield_text_color, $birdfield_default_colors[ 'text_color' ] )) {
$birdfield_css = "
/* Custom Text Color */
.wrapper,
.home #content #blog ul.article .hentry .entry-header .entry-title,
.archive #content ul.list li a .entry-content,
.search #content ul.list li a .entry-content {
color: {$birdfield_text_color};
}
";
wp_add_inline_style( 'birdfield', $birdfield_css );
}
// Custom Link Color
$birdfield_link_color = get_theme_mod( 'birdfield_link_color', $birdfield_default_colors[ 'link_color' ] );
$birdfield_link_color_rgb = birdfield_hex2rgb( $birdfield_link_color );
if( strcasecmp( $birdfield_link_color, $birdfield_default_colors[ 'link_color' ] )) {
$birdfield_css = "
/* Custom Link Color */
a,
#content .pagination a.page-numbers,
#content .pagination .more-link,
#content .hentry .page-links,
#content .hentry .page-links a span,
#content .hentry .more-link,
.home #content #news ul.article li .entry-header .entry-title,
.archive #content ul.list li .entry-header .entry-title,
.search #content ul.list li .entry-header .entry-title,
#content .pagination,
#content .wp-block-button.is-style-outline .wp-block-button__link:not(.has-text-color), #content .wp-block-button.is-style-outline .wp-block-button__link:focus:not(.has-text-color), #content .wp-block-button.is-style-outline .wp-block-button__link:active:not(.has-text-color) {
color: {$birdfield_link_color};
}
#content .pagination a.page-numbers,
#content .pagination .current,
#content .hentry .page-links a,
#content .hentry .page-links span,
#content .hentry .page-links a span {
border-color: {$birdfield_link_color};
}
#content .pagination .current,
#content .hentry .page-links span.current,
#content .wp-block-button a.wp-block-button__link:not(.has-background),
#content .wp-block-file .wp-block-file__button,
input[type=submit], input[type=submit], input[type=button],
button[type=submit], button[type=button] {
background-color: {$birdfield_link_color};
}
#content .wp-block-button a.wp-block-button__link:not(.has-background):hover,
input[type=submit]:hover, input[type=submit]:hover, input[type=button]:hover,
button[type=submit]:hover, button[type=button]:hover {
background-color: rgba( {$birdfield_link_color_rgb}, 0.9 );
}
#content .wp-block-button.is-style-outline .wp-block-button__link:not(.has-text-color):hover,
#content .wp-block-button.is-style-outline .wp-block-button__link:focus:not(.has-text-color):hover,
#content .wp-block-button.is-style-outline .wp-block-button__link:active:not(.has-text-color):hover {
background-color: rgba( {$birdfield_link_color_rgb}, 0.2 );
}
";
wp_add_inline_style( 'birdfield', $birdfield_css );
}
// Custom Header, Footer Background Color
$birdfield_header_color = get_theme_mod( 'birdfield_header_color', $birdfield_default_colors[ 'header_color' ] );
if( strcasecmp( $birdfield_header_color, $birdfield_default_colors[ 'header_color' ] )) {
$birdfield_header_color_rgb = birdfield_hex2rgb( $birdfield_header_color );
$birdfield_css = "
/* Custom Header, Footer Background Color */
#header,
#footer,
#widget-area,
.home #content #blog ul.article .hentry.sticky i span {
background-color: {$birdfield_header_color};
}
#header.mini {
background-color: rgba( {$birdfield_header_color_rgb}, 0.9 );
}
#content .hentry .entry-header .entry-title,
#content .hentry .content-header .content-title,
.home #about .widget h3,
.home #content h2,
.home #content #blog ul.article .hentry.sticky .entry-header .entry-title,
.blog #content #blog ul.article .hentry.sticky .entry-header .entry-title,
#content h1,
#content h2,
#content h3,
#content h4,
#content h5,
#content h6,
#content #comments ol.commentlist li.pingback.bypostauthor .comment-author,
#content #comments ol.commentlist li.comment.bypostauthor .comment-author,
#widget-area .widget #wp-calendar tbody th a,
#widget-area .widget #wp-calendar tbody td a {
color: {$birdfield_header_color};
}
#content h2,
#content h3,
#content .wp-block-separator,
#content .wp-block-pullquote {
border-color: {$birdfield_header_color};
}
@media screen and (min-width: 930px) {
#menu-wrapper .menu ul#menu-primary-items li a:hover {
color: {$birdfield_header_color};
}
#menu-wrapper .menu ul#menu-primary-items li ul li a:hover {
border-color: {$birdfield_header_color};
}
#menu-wrapper .menu ul#menu-primary-items li ul li a {
background-color: {$birdfield_header_color};
}
}
";
wp_add_inline_style( 'birdfield', $birdfield_css );
}
}
add_action( 'wp_enqueue_scripts', 'birdfield_color_css', 11 );
//////////////////////////////////////////////////////
// Excerpt More
function birdfield_excerpt_more($more) {
return '<span class="more-link">' .__( 'Continue reading', 'birdfield' ) . '</span>';
}
add_filter('excerpt_more', 'birdfield_excerpt_more');
//////////////////////////////////////////////////////
// Removing the default gallery style
function birdfield_gallery_atts( $out, $pairs, $atts ) {
$atts = shortcode_atts( array( 'size' => 'medium', ), $atts );
$out['size'] = $atts['size'];
return $out;
}
add_filter( 'shortcode_atts_gallery', 'birdfield_gallery_atts', 10, 3 );
add_filter( 'use_default_gallery_style', '__return_false' );
//////////////////////////////////////////////////////
// Custom Background callback
function birdfield_custom_background_cb() {
// $background is the saved custom image, or the default image.
$background = set_url_scheme( get_background_image() );
// $color is the saved custom color.
// A default has to be specified in style.css. It will not be printed here.
$color = get_background_color();
if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) {
$color = false;
}
if ( ! $background && ! $color )
return;
$style = $color ? "background-color: #$color;" : '';
if ( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
$repeat = 'repeat';
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
$position = 'left';
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
$attachment = 'scroll';
$attachment = " background-attachment: $attachment;";
$style .= $image . $repeat . $position . $attachment;
}
?>
<style type="text/css" id="custom-background-css">
body.custom-background.home #content #news,
body.custom-background.home #content #blog,
body.custom-background .wrapper {
<?php echo trim( $style ); ?>
}
</style>
<?php
}
//////////////////////////////////////////////////////
// Add hook content begin
function birdfield_content_header() {
$birdfield_html = apply_filters( 'birdfield_content_header', '' );
echo $birdfield_html;
}
//////////////////////////////////////////////////////
// Add hook content end
function birdfield_content_footer() {
$birdfield_html = apply_filters( 'birdfield_content_footer', '' );
echo $birdfield_html;
}
//////////////////////////////////////////////////////
// hex color to rgb
function birdfield_hex2rgb ( $hex ) {
$birdfield_hex = preg_replace('/#/', '', $hex);
$birdfield_hex_rgba = hexdec(substr($birdfield_hex, 0, 2));
$birdfield_hex_rgba .= ', ' .hexdec(substr($birdfield_hex, 2, 2));
$birdfield_hex_rgba .= ', ' .hexdec(substr($birdfield_hex, 4, 2));
return $birdfield_hex_rgba;
}
//////////////////////////////////////////////////////
// Custom Header
if ( ! function_exists( 'birdfield_custom_header' )) :
function birdfield_custom_header() {
$birdfield_header_image = get_header_image();
if( ! empty( $birdfield_header_image )){
$birdfield_image_id = attachment_url_to_postid( $birdfield_header_image );
?>
<section id="wall">
<div class="headerimage">
<div class="fixedimage">
<?php
$birdfield_header = get_custom_header();
$birdfield_ratio = intval(( $birdfield_header->height / $birdfield_header->width ) * 100 );
?>
<img src="<?php header_image(); ?>" height="<?php echo $birdfield_header->height; ?>" width="<?php echo $birdfield_header->width; ?>" ratio="<?php echo $birdfield_ratio; ?>%" alt="" />
</div>
</div>
<div class='widget-area-header'>
<?php dynamic_sidebar( 'widget-area-header' ); ?>
</div>
</section>
<?php
return true;
}
return false;
}
endif;
//////////////////////////////////////////////////////
// Header Slider
if ( ! function_exists( 'birdfield_headerslider' )) :
function birdfield_headerslider() {
if (( !is_front_page())) {
return false;
}
if( !get_theme_mod( 'use_slider', false ) ){
return false;
}
$birdfield_interval = get_theme_mod( 'slide_interval', 7000 );
if( 0 == $birdfield_interval){
$birdfield_interval = 7000;
}
// get headerslide option
$birdfield_slides = array();
$birdfield_max = 0;
for( $birdfield_count = 1; $birdfield_count <= 5; $birdfield_count++ ) {
$birdfield_default_image = '';
$birdfield_default_title = '';
$birdfield_default_description = '';
$birdfield_default_link = '';
if( 1 == $birdfield_count ){
$birdfield_default_image = get_template_directory_uri() . '/images/header.jpg';
$birdfield_default_title = __( 'Hello world!','birdfield' );
$birdfield_default_description = __( 'Begin your website.', 'birdfield' );
$birdfield_default_link = '#';
}
$birdfield_image = get_theme_mod( 'slider_image_' .strval( $birdfield_count ), $birdfield_default_image );
if ( ! empty( $birdfield_image )) {
$birdfield_image_id = attachment_url_to_postid( $birdfield_image );
$birdfield_slides[ $birdfield_count -1 ][ 'image' ] = $birdfield_image_id;
$birdfield_slides[ $birdfield_count -1 ][ 'title' ] = get_theme_mod( 'slider_title_' . strval( $birdfield_count ), $birdfield_default_title );
$birdfield_slides[ $birdfield_count -1 ][ 'description' ] = get_theme_mod( 'slider_description_' . strval( $birdfield_count ), $birdfield_default_description );
$birdfield_slides[$birdfield_count -1 ][ 'link' ] = get_theme_mod( 'slider_link_' . strval( $birdfield_count ), $birdfield_default_link );
$birdfield_image_ratio = ( 900 / 1280 ) * 100;
$birdfield_image_src = wp_get_attachment_image_src( $birdfield_image_id, 'full' );
if( $birdfield_image_src ){
$birdfield_image_ratio = intval(( $birdfield_image_src[2] / $birdfield_image_src[1] ) *100 );
}
$birdfield_slides[ $birdfield_count -1 ][ 'ratio' ] = $birdfield_image_ratio .'%';
$birdfield_max++;
}
else{
break;
}
}
if( !$birdfield_max ){
return false;
}
if( 1 < $birdfield_max ){
$birdfield_interval = 'data-interval="' .$birdfield_interval .'"';
}
else{
$birdfield_interval = '';
}
?>
<section id="wall">
<div class="headerimage slider" <?php echo $birdfield_interval; ?>>
<?php
// sort randam
$birdfield_html = '';
$birdfield_start = mt_rand( 1, $birdfield_max );
for( $birdfield_count = 1; $birdfield_count <= $birdfield_max; $birdfield_count++ ) {
$birdfield_class = '';
if( $birdfield_start == $birdfield_count ){
$birdfield_class = ' start active';
}
$birdfield_html .= '<div class="slideitem' .$birdfield_class .'" id="slideitem_' .$birdfield_count .'">';
$birdfield_html .= '<div class="fixedimage">';
$birdfield_html .= wp_get_attachment_image( $birdfield_slides[ $birdfield_count -1 ][ 'image' ], 'full', 0, array( 'ratio' => $birdfield_slides[ $birdfield_count -1 ][ 'ratio' ] ));
$birdfield_html .= '</div>';
$birdfield_html .= '<div class="caption">';
$birdfield_html .= '<p><strong>' .$birdfield_slides[ $birdfield_count -1 ][ 'title' ] .'</strong><span>' .$birdfield_slides[ $birdfield_count -1 ][ 'description' ] .'</span></p>';
if( ! empty( $birdfield_slides[ $birdfield_count -1 ][ 'link' ] )){
$birdfield_html .= '<a href="' .$birdfield_slides[ $birdfield_count -1 ][ 'link' ] .'">' .__( 'More', 'birdfield' ) .'</a>';
}
$birdfield_html .= '</div>';
$birdfield_html .= '</div>';
}
echo $birdfield_html;
?>
</div>
</section>
<?php
return true;
}
endif;