-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
972 lines (775 loc) · 30.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
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
<?php
// Load main options panel file
if ( !function_exists( 'optionsframework_init' ) ) {
define('OPTIONS_FRAMEWORK_URL', TEMPLATEPATH . '/admin/');
define('OPTIONS_FRAMEWORK_DIRECTORY', get_bloginfo('template_directory') . '/admin/');
require_once (OPTIONS_FRAMEWORK_URL . 'options-framework.php');
}
// Load Mr MetaBox
if(!class_exists('mrMetaBox')) {
define('MRMETABOX_URL', TEMPLATEPATH . '/admin/mr-meta-box/');
require_once(MRMETABOX_URL . 'mr-meta-box.php');
}
// Enable translation
// Translations can be put in the /languages/ directory
load_theme_textdomain( 'themetrust', TEMPLATEPATH . '/languages' );
// Widgets
require_once (TEMPLATEPATH . '/admin/widgets.php');
// Mobile device detection
if( !function_exists('mobile_user_agent_switch') ){
function is_mobile(){
$device = '';
if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
$device = "ipad";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
$device = "iphone";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
$device = "blackberry";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
$device = "android";
}
if( $device ) {
return $device;
} return false; {
return false;
}
}
}
// Disable Updates
function ttrust_hidden_theme( $r, $url ) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/themes/update-check/1.0/' ) )
return $r; // Not a theme update request. Bail immediately.
$themes = unserialize( $r['body']['themes'] );
unset( $themes[ get_option( 'template' ) ] );
unset( $themes[ get_option( 'stylesheet' ) ] );
$r['body']['themes'] = serialize( $themes );
return $r;
}
add_filter( 'http_request_args', 'ttrust_hidden_theme', 5, 2 );
// Add Browser to body class
add_filter('body_class','browser_body_class');
function browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) $classes[] = 'ie';
else $classes[] = 'unknown';
if($is_iphone) $classes[] = 'iphone';
return $classes;
}
//////////////////////////////////////////////////////////////
// Theme Header
/////////////////////////////////////////////////////////////
add_action('wp_enqueue_scripts', 'ttrust_scripts');
function ttrust_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('superfish', get_bloginfo('template_url').'/js/superfish.js', array('jquery'), '1.4.8', true);
wp_enqueue_style('superfish', get_bloginfo('template_url').'/css/superfish.css', false, '1.4.8', 'all' );
if(is_active_widget(false,'','ttrust_flickr')) :
wp_enqueue_script('flickrfeed', get_bloginfo('template_url').'/js/jflickrfeed.js', array('jquery'), '0.8', true);
endif;
wp_enqueue_script('fitvids', get_bloginfo('template_url').'/js/jquery.fitvids.js', array('jquery'), '1.0', true);
wp_enqueue_script('actual', get_bloginfo('template_url').'/js/jquery.actual.min.js', array('jquery'), '1.8.13', true);
wp_enqueue_script('fittext', get_bloginfo('template_url').'/js/jquery.fittext.js', array('jquery'), '1.0', true);
wp_enqueue_script('tinynav', get_bloginfo('template_url').'/js/tinynav.min.js', array('jquery'), '1.05', true);
wp_enqueue_script('isotope', get_bloginfo('template_url').'/js/jquery.isotope.min.js', array('jquery'), '1.3.110525', true);
wp_enqueue_style('slideshow', get_bloginfo('template_url').'/css/flexslider.css', false, '1.8', 'all' );
wp_enqueue_script('slideshow', get_bloginfo('template_url').'/js/jquery.flexslider-min.js', array('jquery'), '1.8', true);
wp_enqueue_script('theme_trust_js', get_bloginfo('template_url').'/js/theme_trust.js', array('jquery'), '1.0', true);
}
add_action('wp_head','ttrust_theme_head');
function ttrust_theme_head() { ?>
<meta name="generator" content="<?php global $ttrust_theme, $ttrust_version; echo $ttrust_theme.' '.$ttrust_version; ?>" />
<style type="text/css" media="screen">
<?php $menu_font = of_get_option('ttrust_menu_font'); ?>
<?php $heading_font = of_get_option('ttrust_heading_font'); ?>
<?php $sub_heading_font = of_get_option('ttrust_sub_heading_font'); ?>
<?php $body_font = of_get_option('ttrust_body_font'); ?>
<?php $slideshow_heading_font = of_get_option('ttrust_slideshow_heading_font'); ?>
<?php $slideshow_description_font = of_get_option('ttrust_slideshow_description_font'); ?>
<?php if ($menu_font) : ?>
#mainNav ul a{ font-family: '<?php echo $menu_font; ?>'; }
<?php endif; ?>
<?php if ($heading_font) : ?>
h1, h2, h3, h4, h5, h6, .homeSection h3, #pageHead h1 { font-family: '<?php echo $heading_font; ?>' !important; }
<?php endif; ?>
<?php if ($sub_heading_font) : ?>
.sectionHead p{ font-family: '<?php echo $sub_heading_font; ?>'; }
<?php endif; ?>
<?php if ($body_font) : ?>
body { font-family: '<?php echo $body_font; ?>'; }
<?php endif; ?>
<?php if ($slideshow_heading_font) : ?>
.home .slideshow h2 { font-family: '<?php echo $slideshow_heading_font; ?>' !important; }
<?php endif; ?>
<?php if ($slideshow_description_font) : ?>
.home .slideshow p { font-family: '<?php echo $slideshow_description_font; ?>'; }
<?php endif; ?>
<?php if(of_get_option('ttrust_banner_text_position')) : ?>
#bannerText { top: <?php echo(of_get_option('ttrust_banner_text_position')); ?>px; }
<?php endif; ?>
<?php if(of_get_option('ttrust_color_header')) : ?>
#header {
background-color: <?php echo(of_get_option('ttrust_color_header')); ?>;
}
#mainNav ul ul {
background-color: <?php echo(of_get_option('ttrust_color_header')); ?>;
}
<?php endif; ?>
<?php if(of_get_option('ttrust_color_accent')) : ?>
blockquote, address {
border-left: 5px solid <?php echo(of_get_option('ttrust_color_accent')); ?>;
}
#filterNav .selected, #filterNav a.selected:hover {
background-color: <?php echo(of_get_option('ttrust_color_accent')); ?>;
}
#content .project.small .title span{
background-color: <?php echo(of_get_option('ttrust_color_accent')); ?> !important;
}
.flex-direction-nav li a {
background-color: <?php echo(of_get_option('ttrust_color_accent')); ?> !important;
}
.posts .post .date
{
background-color: <?php echo(of_get_option('ttrust_color_accent')); ?> !important;
}
<?php endif; ?>
<?php if (of_get_option('ttrust_google_map_height')) : ?>
#googleMap {height: <?php echo of_get_option('ttrust_google_map_height');?>px;}
<?php endif; ?>
<?php if(of_get_option('ttrust_color_link')) : ?>a { color: <?php echo(of_get_option('ttrust_color_link')); ?>;}<?php endif; ?>
<?php if(of_get_option('ttrust_color_link_hover')) : ?>a:hover {color: <?php echo(of_get_option('ttrust_color_link_hover')); ?>;}<?php endif; ?>
<?php if(of_get_option('ttrust_color_btn')) : ?>.button, #searchsubmit, input[type="submit"] {background-color: <?php echo(of_get_option('ttrust_color_btn')); ?> !important;}<?php endif; ?>
<?php if ( is_archive() ): ?> html {height: 101%;} <?php endif; ?>
<?php echo(of_get_option('ttrust_custom_css')); ?>
</style>
<!--[if IE 7]>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/ie7.css" type="text/css" media="screen" />
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/ie8.css" type="text/css" media="screen" />
<![endif]-->
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<?php echo "\n".of_get_option('ttrust_analytics')."\n"; ?>
<?php }
add_action('init', 'remheadlink');
function remheadlink() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
}
//////////////////////////////////////////////////////////////
// Custom Background Support
/////////////////////////////////////////////////////////////
add_theme_support( 'custom-background' );
//////////////////////////////////////////////////////////////
// Body Class
/////////////////////////////////////////////////////////////
function ttrust_body_classes($classes) {
$has_slideshow = of_get_option('ttrust_slideshow_enabled');
$c = (!isset($has_slideshow) || $has_slideshow ? "has-slideshow" : "");
$classes[] = $c;
return $classes;
}
add_filter('body_class','ttrust_body_classes');
//////////////////////////////////////////////////////////////
// Theme Footer
/////////////////////////////////////////////////////////////
add_action('wp_footer','ttrust_footer');
function ttrust_footer() {
wp_reset_query();
global $wp_query;
global $post;
include(TEMPLATEPATH . '/js/slideshow.php');
if(of_get_option('ttrust_google_map_address')) :
include(TEMPLATEPATH . '/js/google_map.php');
endif;
}
//////////////////////////////////////////////////////////////
// Remove
/////////////////////////////////////////////////////////////
// #more from more-link
function ttrust_remove($content) {
global $id;
return str_replace('#more-'.$id.'"', '"', $content);
}
add_filter('the_content', 'ttrust_remove');
//////////////////////////////////////////////////////////////
// Custom Excerpt
/////////////////////////////////////////////////////////////
function excerpt_ellipsis($text) {
return str_replace('[...]', '...', $text);
}
add_filter('the_excerpt', 'excerpt_ellipsis');
//////////////////////////////////////////////////////////////
// Add Excerpt Support for Pages
/////////////////////////////////////////////////////////////
add_post_type_support( 'page', 'excerpt' );
//////////////////////////////////////////////////////////////
// Get Meta Box Value
/////////////////////////////////////////////////////////////
function get_meta_box_vlaue($m) {
global $wp_query;
global $post;
$meta_box_value = get_post_meta($post->ID, $m, true);
return $meta_box_value;
}
//////////////////////////////////////////////////////////////
// Pagination Styles
/////////////////////////////////////////////////////////////
add_action( 'wp_print_styles', 'ttrust_deregister_styles', 100 );
function ttrust_deregister_styles() {
wp_deregister_style( 'wp-pagenavi' );
}
remove_action('wp_head', 'pagenavi_css');
remove_action('wp_print_styles', 'pagenavi_stylesheets');
//////////////////////////////////////////////////////////////
// Navigation Menus
/////////////////////////////////////////////////////////////
add_theme_support('menus');
register_nav_menu('main', 'Main Navigation Menu');
function default_nav() {
echo '<ul class="sf-menu clearfix" >';
wp_list_pages('sort_column=menu_order&title_li=');
echo '</ul>';
}
//////////////////////////////////////////////////////////////
// Feature Images (Post Thumbnails)
/////////////////////////////////////////////////////////////
add_theme_support('post-thumbnails');
set_post_thumbnail_size(100, 100, true);
add_image_size('ttrust_post_thumb_big', 990, 260, true);
add_image_size('ttrust_post_thumb_small', 150, 150, true);
add_image_size('ttrust_post_thumb_tiny', 50, 50, true);
add_image_size('ttrust_one_third_cropped', 300, 240, true);
add_image_size('ttrust_square_medium', 190, 190, true);
//////////////////////////////////////////////////////////////
// Button Shortcode
/////////////////////////////////////////////////////////////
function ttrust_button($a) {
extract(shortcode_atts(array(
'label' => 'Button Text',
'id' => '1',
'url' => '',
'target' => '_parent',
'size' => '',
'color' => '',
'ptag' => false
), $a));
$link = $url ? $url : get_permalink($id);
$s = "";
if($color) $s .= "background-color:".$color." !important;";
if($ptag) :
return wpautop('<a href="'.$link.'" target="'.$target.'" style="'.$s.'" class="button '.$size.'">'.$label.'</a>');
else :
return '<a href="'.$link.'" target="'.$target.'" style="'.$s.'" class="button '.$size.'">'.$label.'</a>';
endif;
}
add_shortcode('button', 'ttrust_button');
//////////////////////////////////////////////////////////////
// Column Shortcodes
/////////////////////////////////////////////////////////////
function ttrust_one_third( $atts, $content = null ) {
return '<div class="one_third column">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_third', 'ttrust_one_third');
function ttrust_one_third_last( $atts, $content = null ) {
return '<div class="one_third column last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_third_last', 'ttrust_one_third_last');
function ttrust_two_third( $atts, $content = null ) {
return '<div class="two_third column">' . do_shortcode($content) . '</div>';
}
add_shortcode('two_third', 'ttrust_two_third');
function ttrust_two_third_last( $atts, $content = null ) {
return '<div class="two_third column last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('two_third_last', 'ttrust_two_third_last');
function ttrust_one_half( $atts, $content = null ) {
return '<div class="one_half column">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_half', 'ttrust_one_half');
function ttrust_one_half_last( $atts, $content = null ) {
return '<div class="one_half column last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_half_last', 'ttrust_one_half_last');
function ttrust_one_fourth( $atts, $content = null ) {
return '<div class="one_fourth column">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_fourth', 'ttrust_one_fourth');
function ttrust_one_fourth_last( $atts, $content = null ) {
return '<div class="one_fourth column last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_fourth_last', 'ttrust_one_fourth_last');
function ttrust_three_fourth( $atts, $content = null ) {
return '<div class="three_fourth column">' . do_shortcode($content) . '</div>';
}
add_shortcode('three_fourth', 'ttrust_three_fourth');
function ttrust_three_fourth_last( $atts, $content = null ) {
return '<div class="three_fourth column last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('three_fourth_last', 'ttrust_three_fourth_last');
function ttrust_reformat($content) {
$new_content = '';
/* Matches the contents and the open and closing tags */
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
/* Matches just the contents */
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
/* Divide content into pieces */
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
/* Loop over pieces */
foreach ($pieces as $piece) {
/* Look for presence of the shortcode */
if (preg_match($pattern_contents, $piece, $matches)) {
/* Append to content (no formatting) */
$new_content .= $matches[1];
} else {
/* Format and append to content */
$new_content .= wptexturize(wpautop($piece));
}
}
return $new_content;
}
// Remove the 2 main auto-formatters
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
// Before displaying for viewing, apply this function
add_filter('the_content', 'ttrust_reformat', 99);
add_filter('widget_text', 'ttrust_reformat', 99);
//////////////////////////////////////////////////////////////
// Slideshow Shortcode
/////////////////////////////////////////////////////////////
function ttrust_slideshow( $atts, $content = null ) {
$content = str_replace('<br />', '', $content);
$content = str_replace('<img', '<li><img', $content);
$content = str_replace('/>', '/></li>', $content);
return '<div class="flexslider clearfix"><ul class="slides">' . $content . '</ul></div>';
}
add_shortcode('slideshow', 'ttrust_slideshow');
//////////////////////////////////////////////////////////////
// Elastic Video
/////////////////////////////////////////////////////////////
function ttrust_elasticVideo( $atts, $content = null ) {
return '<div class="videoContainer">' . $content . '</div>';
}
add_shortcode('elastic-video', 'ttrust_elasticVideo');
//////////////////////////////////////////////////////////////
// Add conainers to all videos
/////////////////////////////////////////////////////////////
function add_video_containers($content) {
$content = str_replace('<object', '<div class="videoContainer"><object', $content);
$content = str_replace('</object>', '</object></div>', $content);
$content = str_replace('<embed', '<div class="videoContainer"><embed', $content);
$content = str_replace('</embed>', '</embed></div>', $content);
$content = str_replace('<iframe', '<div class="videoContainer"><iframe', $content);
$content = str_replace('</iframe>', '</iframe></div>', $content);
return $content;
}
add_action('the_content', 'add_video_containers');
//////////////////////////////////////////////////////////////
// Custom More Link
/////////////////////////////////////////////////////////////
function more_link() {
global $post;
$more_link = '<p class="moreLink"><a href="'.get_permalink().'" title="'.get_the_title().'">';
$more_link .= '<span>'.__('Read More', 'themetrust').'</span>';
$more_link .= '</a></p>';
echo $more_link;
}
//////////////////////////////////////////////////////////////
// Custom Sanitize for Theme Options
/////////////////////////////////////////////////////////////
add_action('admin_init','optionscheck_change_santiziation', 100);
function optionscheck_change_santiziation() {
remove_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
add_filter( 'of_sanitize_textarea', 'custom_sanitize_textarea' );
}
function custom_sanitize_textarea($input) {
global $allowedposttags;
$custom_allowedtags["script"] = array();
$custom_allowedtags["iframe"] = array(
"src" => array(),
"width" => array(),
"height" => array(),
"scrolling" => array(),
"marginheight" => array(),
"marginwidth" => array()
);
$custom_allowedtags = array_merge($custom_allowedtags, $allowedposttags);
$output = wp_kses( $input, $custom_allowedtags);
return $output;
}
//////////////////////////////////////////////////////////////
// Custom Post Types and Custom Taxonamies
/////////////////////////////////////////////////////////////
function register_projects() {
$labels = array(
'name' => __( 'Projects' ),
'singular_name' => __( 'Project' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Project' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit Project' ),
'new_item' => __( 'New Project' ),
'view' => __( 'View Project' ),
'view_item' => __( 'View Project' ),
'search_items' => __( 'Search Projects' ),
'not_found' => __( 'No projects found' ),
'not_found_in_trash' => __( 'No projects found in Trash' ),
'parent' => __( 'Parent Project' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'menu_icon' => get_template_directory_uri(). '/images/blue-folder-stand.png',
'query_var' => true,
'rewrite' => array( 'slug' => 'project', 'hierarchical' => true, 'with_front' => false ),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'thumbnail', 'comments', 'revisions', 'excerpt')
);
register_post_type( 'project' , $args );
}
// Add Portfolio & Thumbnail to Admin Listing
add_action( 'manage_project_posts_custom_column' , 'custom_project_column', 10, 2 );
function set_project_columns($columns) {
return array(
'cb' => '<input type="checkbox" />',
'title' => __('Title'),
'thumbnail' => __('Thumbnail'),
'skill' => __('Skill'),
'author' => __('Author'),
'date' => __('Date')
);
}
add_filter('manage_project_posts_columns' , 'set_project_columns');
function set_custom_edit_project_columns($columns) {
return $columns
+ array('skill' => __('Skill'));
+ array('thumbnail' => __('Thumbnail'));
}
function custom_project_column( $column, $post_id ) {
global $post;
switch ( $column ) {
case 'skill':
$terms = get_the_term_list( $post_id , 'skill' , '' , ',' , '' );
if ( is_string( $terms ) ) {
echo $terms;
} else {
echo 'Unable to get skill(s)';
}
break;
case 'thumbnail':
$thumbnail = get_the_post_thumbnail($post->ID, array(70,70));
if ( is_string( $thumbnail ) ) {
echo $thumbnail;
} else {
echo 'Unable to get thumbnail(s)';
}
break;
}
}
function register_skills() {
$labels = array(
'name' => __( 'Skills' ),
'singular_name' => __( 'Skill' ),
'search_items' => __( 'Search Skills' ),
'all_items' => __( 'All Skills' ),
'parent_item' => __( 'Parent Skill' ),
'parent_item_colon' => __( 'Parent Skill:' ),
'edit_item' => __( 'Edit Skill' ),
'update_item' => __( 'Update Skill' ),
'add_new_item' => __( 'Add New Skill' ),
'new_item_name' => __( 'New Skill Name' )
);
register_taxonomy('skill','project',array(
'hierarchical' => false,
'labels' => $labels
));
}
// Slide post type
function register_slides() {
register_post_type( 'slide',
array(
'labels' => array(
'name' => __( 'Slides', 'themetrust'),
'menu_name' => __( 'Slides', 'themetrust'),
'singular_name' => __( 'Slide', 'themetrust'),
'all_items' => __( 'All Slides', 'themetrust'),
'add_new' => __( 'Add New', 'themetrust' ),
'add_new_item' => __( 'Add New Slide', 'themetrust' ),
'edit_item' => __( 'Edit Slide', 'themetrust' ),
'new_item' => __( 'New Slide', 'themetrust' ),
'view_item' => __( 'View Slide', 'themetrust' ),
'search_items' => __( 'Search Slides', 'themetrust' ),
'not_found' => __( 'No slides found', 'themetrust' ),
'not_found_in_trash' => __( 'No slides found in Trash', 'themetrust' )
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'menu_icon' => get_template_directory_uri(). '/images/image-empty.png',
'show_in_menu' => true,
'show_in_nav_menus' => false,
'menu_position ' => 20,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'hierarchical' => false,
'has_archive' => true,
'rewrite' => 'slide'
)
);
}
// Testimonial post type
function register_testimonials() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'Testimonials', 'themetrust'),
'menu_name' => __( 'Testimonials', 'themetrust'),
'singular_name' => __( 'Testimonial', 'themetrust'),
'all_items' => __( 'All Testimonials', 'themetrust'),
'add_new' => __( 'Add New', 'themetrust' ),
'add_new_item' => __( 'Add New Slide', 'themetrust' ),
'edit_item' => __( 'Edit Testimonial', 'themetrust' ),
'new_item' => __( 'New Testimonial', 'themetrust' ),
'view_item' => __( 'View Testimonial', 'themetrust' ),
'search_items' => __( 'Search Testimonials', 'themetrust' ),
'not_found' => __( 'No slides found', 'themetrust' ),
'not_found_in_trash' => __( 'No testimonials found in Trash', 'themetrust' )
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'menu_position ' => 20,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'hierarchical' => false,
'has_archive' => true,
'rewrite' => 'testimonial'
)
);
}
function custom_flush_rules(){
//defines the post type so the rules can be flushed.
register_slides();
register_testimonials();
register_projects();
register_skills();
//and flush the rules.
flush_rewrite_rules();
}
add_action('after_switch_theme', 'custom_flush_rules');
add_action( 'init', 'register_projects' );
add_action( 'init', 'register_skills' );
add_action( 'init', 'register_slides' );
add_action( 'init', 'register_testimonials' );
// List custom post type taxonomies
function ttrust_get_terms( $id = '' ) {
global $post;
if ( empty( $id ) )
$id = $post->ID;
if ( !empty( $id ) ) {
$post_taxonomies = array();
$post_type = get_post_type( $id );
$taxonomies = get_object_taxonomies( $post_type , 'names' );
foreach ( $taxonomies as $taxonomy ) {
$term_links = array();
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) )
return $terms;
if ( $terms ) {
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) )
return $link;
$term_links[] = '<li><span><a href="'.$link.'">' . $term->name . '</a></span></li>';
}
}
$term_links = apply_filters( "term_links-$taxonomy" , $term_links );
$post_terms[$taxonomy] = $term_links;
}
return $post_terms;
} else {
return false;
}
}
function ttrust_get_terms_list( $id = '' , $echo = true ) {
global $post;
if ( empty( $id ) )
$id = $post->ID;
if ( !empty( $id ) ) {
$my_terms = ttrust_get_terms( $id );
if ( $my_terms ) {
$my_taxonomies = array();
foreach ( $my_terms as $taxonomy => $terms ) {
$my_taxonomy = get_taxonomy( $taxonomy );
if ( !empty( $terms ) ) $my_taxonomies[] = implode( $terms);
}
if ( !empty( $my_taxonomies ) ) {
$output = "";
foreach ( $my_taxonomies as $my_taxonomy ) {
$output .= $my_taxonomy . "\n";
}
}
if ( $echo )
if(isset($output)) echo $output;
else
if(isset($output)) return $output;
} else {
return;
}
} else {
return false;
}
}
//////////////////////////////////////////////////////////////
// Meta Box
/////////////////////////////////////////////////////////////
$prefix = "_ttrust_";
$text_alignment = array("center" => "Center", "left" => "Left", "right" => "Right");
//Project options
$config = array(
'id' => 'project_options',
'title' => 'Project Options',
'prefix' => $prefix."project_",
'postType' => array('project'),
'context' => 'side',
'priority' => 'default',
'usage' => 'theme',
'showInColumns' => false
);
$project_options_meta_box = new mrMetaBox($config);
$project_options_meta_box->addField(array(
'type' => 'Checkbox',
'id' => 'featured',
'label' => __('Feature on Home: ','themetrust')
));
//Page Options
$config = array(
'id' => 'page_options',
'title' => 'Page Options',
'prefix' => $prefix."page_",
'postType' => array('page'),
'context' => 'side',
'priority' => 'default',
'usage' => 'theme',
'showInColumns' => false
);
$page_options_meta_box = new mrMetaBox($config);
$page_options_meta_box->addField(array(
'type' => 'Textarea',
'id' => 'description',
'label' => __('Page Description: ','themetrust')
));
$page_options_meta_box->addField(array(
'type' => 'Textarea',
'id' => 'skills',
'label' => __('Skills: ','themetrust')
));
$page_options_meta_box->addField(array(
'type' => 'Checkbox',
'id' => 'featured',
'label' => __('Feature on Home: ','themetrust')
));
//Slide options
$config = array(
'id' => 'slide_options',
'title' => 'Slide Options',
'prefix' => $prefix."slide_",
'postType' => array('slide'),
'context' => 'normal',
'priority' => 'high',
'usage' => 'theme',
'showInColumns' => true
);
$slide_options_meta_box = new mrMetaBox($config);
$slide_options_meta_box->addField(array(
'type' => 'Textarea',
'id' => 'description',
'label' => __('Description: ','themetrust')
));
$slide_options_meta_box->addField(array(
'type' => 'Select',
'id' => "text_alignment",
'label' => __('Text Alignment: ','themetrust'),
'default' => '',
'options' => $text_alignment
));
$slide_options_meta_box->addField(array(
'type' => 'Image',
'id' => 'background_image',
'label' => __('Background Image: ','themetrust'),
'attachToPost' => false
));
$slide_options_meta_box->addField(array(
'type' => 'Checkbox',
'id' => 'show_text',
'label' => __('Show Text: ','themetrust')
));
//////////////////////////////////////////////////////////////
// Comments
/////////////////////////////////////////////////////////////
function ttrust_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li id="li-comment-<?php comment_ID() ?>">
<div class="comment <?php echo get_comment_type(); ?>" id="comment-<?php comment_ID() ?>">
<?php echo get_avatar($comment,'70',get_bloginfo('template_url').'/images/default_avatar.png'); ?>
<h5><?php comment_author_link(); ?></h5>
<span class="date"><?php comment_date(); ?></span>
<?php if ($comment->comment_approved == '0') : ?>
<p><span class="message"><?php _e('Your comment is awaiting moderation.', 'themetrust'); ?></span></p>
<?php endif; ?>
<?php comment_text() ?>
<?php
if(get_comment_type() != "trackback")
comment_reply_link(array_merge( $args, array('add_below' => 'comment','reply_text' => '<span>'. __('Reply', 'themetrust') .'</span>', 'login_text' => '<span>'. __('Log in to reply', 'themetrust') .'</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'])))
?>
</div><!-- end comment -->
<?php
}
function ttrust_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li class="comment" id="comment-<?php comment_ID() ?>"><?php comment_author_link(); ?> - <?php comment_excerpt(); ?>
<?php
}
//////////////////////////////////////////////////////////////
// Pagination function // http://goo.gl/njhZ
/////////////////////////////////////////////////////////////
function kriesi_pagination($pages = '', $range = 2) {
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class='pagination clearfix'><div class='inside'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div></div>\n";
}
}
?>