Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
896 lines (715 loc) · 30.6 KB
/
Copy pathfunctions.php
File metadata and controls
896 lines (715 loc) · 30.6 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
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
<?php
/****************************************************************************************************************************/
/* WARNING!!!! NEVER CHANGE ANYTHING IN THIS FILE OR FOLDER!!! USE A CHILD THEME INSTEAD! */
/* CHECK OUT "STARTER_CHILD" FOLDER FOR INSTRUCTIONS */
/*****************************************************************************************************************************
Many of the functions in this file can be rewritten by creating functions with an identical name in a child theme
Just copy what's inside the
if ( ! function_exists()){
COPY THIS STUFF
}
Then paste it into your child's functions.php and change away.
*/
include_once( 'functions-actions.php' );
add_theme_support( 'automatic-feed-links' );
/********************************************************************************
Here's where you get to set up the widths of your columns. If you change
the number of columns you may need to redefine cogito_wp_get_cols in this
file
ALL SECTIONS MUST ADD UP TO 'total_columns' (or not. maybe you like the look of a broken site)
*********************************************************************************/
if (!isset($cogito_init) ){
$cogito_init = array(
// Set this to be the same as in _settings.scss. This is the size of your grid.
'total_columns' => 12,
//Three columns with right and left sidebar
'three_columns_left' => 3,
'three_columns_content' => 6,
'three_columns_right' => 3,
//Two columns with right sidebar
'two_columns_rsb_right' => 4,
'two_columns_rsb_content' => 8,
//Two columns with Left sidebar
'two_columns_lsb_left' => 3,
'two_columns_lsb_content' => 9,
//1 Column. Centered by default
'one_column_content' => 10,
/******************************************************************************************************
* Sets an array corresponding to the number and widths of your footers from left to right.
* You can have as many footers as you want but the widths MUST add up to total_columns or Foundation columns
* will hate you and stop answering your phone calls.
*
* Example: 3 columns of equal width array(4,4,4);
2 columns of widths 4 and 8 array(4,8);
*****************************************************************************************************/
'footers' => array( 4,3,5 )
);
}
update_option( 'cogito_init', $cogito_init );
/**
* Debugger function to output an array (only if logged in and administrator)
**/
function d($obj, $title=""){
if ( current_user_can( 'manage_options' ) ) {
print "<div class='wp-debugger' style='border: 1px solid black; padding: 2rem; margin: 2rem;'><h3>$title</h3><pre>" . htmlentities(print_r($obj,1), ENT_QUOTES, "UTF-8"). "</pre></div>";
}
}
if ( ! function_exists( 'cogito_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
* Create your own twentyeleven_posted_on to override in a child theme
*
* @since Twenty Eleven 1.0
*/
function cogito_posted_on() {
$data = array(
'permalink' => esc_url( get_permalink() ),
'time' => esc_attr( get_the_time() ),
'date_year' => esc_attr( get_the_date( 'c' ) ),
'date' => esc_attr( get_the_date() ),
'author_url' => esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
'all_posts_by' => esc_attr( sprintf( __( 'View all posts by %s', 'cogito_wp' ), get_the_author() ) ),
'author' => get_the_author()
);
$data['output'] = sprintf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'cogito_wp' ),
$data['permalink'],
$data['time'],
$data['date_year'],
$data['date'],
$data['author_url'],
$data['all_posts_by'],
$data['author']
);
$data = apply_filters('cogito_posted_on', $data );
print $data['output'];
}
endif;
//Wrap the video in foundation's video thingy
function cogito_video_wrap($html, $url, $args){
if (preg_match('/^http:\/\/(www\.)?youtube.com\/watch.*/i', $url) ||
preg_match('/^http:\/\/youtu.be\/*/i', $url) ) {
$html = "<div class='flex-video'>" . $html . "</div>";
}
return $html;
}
add_filter( 'embed_oembed_html', 'cogito_video_wrap', 10, 3);
/**********************************************
Load in the stylesheets we need.
This takes a lot of tweaking because of how
problematic wordpress is with conditional
stylesheets
***********************************************/
function cogito_enqueue_styles() {
// Add conditional stylesheets for lesser browsers
$maxIE = 9; //the top version of IE that we make exceptions for
// Now load each css file if and only if there is a file that exists for this version
for ($i = 6; $i <= $maxIE; $i++){
if( is_file( get_stylesheet_directory() . '/css/ie'.$i.'.css') ){
wp_register_style( 'app-ie'.$i, get_stylesheet_directory_uri() . '/css/ie'.$i.'.css' );
$GLOBALS['wp_styles']->add_data( 'app-ie' . $i , 'conditional', 'IE '.$i );
wp_enqueue_style( 'app-ie'.$i );
}
else {
wp_register_style( 'app-ie'.$i, get_stylesheet_directory_uri() . '/css/app.css' );
$GLOBALS['wp_styles']->add_data( 'app-ie' . $i , 'conditional', 'IE '.$i );
wp_enqueue_style( 'app-ie'.$i );
}
}
}
add_action( 'wp_enqueue_scripts', 'cogito_enqueue_styles' );
/**********************************************
Simple Pagination
***********************************************/
function cogito_wp_simple_pagination($pagenum, $numpages=0)
{
if ($pagenum < 1) $pagenum =1;
$paged_formal = "pagenum=";
$otherfields="";
foreach($_GET as $key => $getparam){
if ($key != "pagenum"){
$otherfields .="&$key=$getparam";
}
}
if($numpages > 0){ ?>
<p class="paginator">
<?php
if ($pagenum > 1) { ?>
<a href="<?php echo '?'.$paged_formal . ($pagenum -1) . $otherfields; ?>"><</a>
<?php }
for($i=1;$i<=$numpages;$i++){?>
<?php $selected = 'class="selected" style="color:red;"';?>
<a href="<?php echo '?'.$paged_formal. $i . $otherfields; ?>" <?php ($pagenum==$i)? print $selected : null;?>><?php echo $i;?></a>
<?php } ?>
<?php if($pagenum < $numpages){?>
<a href="<?php echo '?'.$paged_formal. ($pagenum +1) . $otherfields; ?>">></a>
<?php } ?>
</p>
<?php }
}
/**********************************************
Do shortcode in WIDGETS.
(note: THIS=AWESOME )
***********************************************/
add_filter('widget_text', 'do_shortcode');
/**
* This function returns the columns and widths to be populated as classes.
* It is recommended that you have this in your child's functions.php file
* since this is what will let you change the column widths
*/
if ( ! function_exists( 'cogito_wp_col_class' ) ) :
function cogito_wp_col_class($col = ''){
$cogito_init = get_option('cogito_init');
$val = false;
$widget_list = wp_get_sidebars_widgets();
//Is there a left column?
if ( isset($widget_list['sidebar-left']) && !empty($widget_list['sidebar-left']) ) {
$left = true;
}
//Is there a right column?
if ( isset($widget_list['sidebar-right']) && !empty($widget_list['sidebar-right']) ) {
$right = true;
}
//It's a 3-column layout with a left and right sidebar.
if ( isset($left) && isset($right) ) {
switch ($col) {
case 'content': $val = 'large-' . $cogito_init['three_columns_content'] . " columns push-". $cogito_init['three_columns_left']; break;
case 'left': $val = 'large-' . $cogito_init['three_columns_left'] . " columns pull-" . $cogito_init['three_columns_content']; break;
case 'right': $val = 'large-' . $cogito_init['three_columns_right'] . " columns"; break;
}
}
//It's a 2-column layout with a left sidebar.
elseif ( isset($left) ){
switch ($col) {
case 'content': $val = 'large-'. $cogito_init['two_columns_lsb_content'] . " columns push-" . $cogito_init['two_columns_lsb_left']; break;
case 'left': $val = 'large-'. $cogito_init['two_columns_lsb_left'] . " columns pull-" . $cogito_init['two_columns_lsb_content']; break;
}
}
//It's a 2-column layout with a right sidebar.
elseif ( isset($right) ){
switch ($col) {
case 'content': $val = 'large-'. $cogito_init['two_columns_rsb_content'] . " columns"; break;
case 'right': $val = 'large-'. $cogito_init['two_columns_rsb_right'] . " columns"; break;
}
}
//It's a 1-column layout.
else {
switch ($col) {
case 'content': $val = 'large-'. $cogito_init['one_column_content'] . " centered columns"; break;
}
}
return $val;
}
endif;
/**
* Foundation is what we base our themes on
*
* Let's add all the necessary javascript and styles
*/
if ( ! function_exists( 'cogito_wp_admin_enqueue_scripts' ) ) :
function cogito_wp_admin_enqueue_scripts( $hook_suffix ) {
// Foundation gets its own jquery
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' );
wp_enqueue_script( 'jquery' );
//App.js just contains some extra form stuff for now.
wp_enqueue_script( 'foundation-min', get_template_directory_uri() . '/js/foundation.min.js', array('jquery') );
wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/js/vendor/custom.modernizr.js' );
// I'm not sure of the best way to do this. Would be nice to have as a menu with checkboxes on the back end.
// wp_enqueue_script( 'foundation-alerts', get_template_directory_uri() . '/js/foundation.alerts.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-clearing', get_template_directory_uri() . '/js/foundation.clearing.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-cookie', get_template_directory_uri() . '/js/foundation.cookie.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-dropdown', get_template_directory_uri() . '/js/foundation.dropdown.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-forms', get_template_directory_uri() . '/js/foundation.forms.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-interchange', get_template_directory_uri() . '/js/foundation.interchange.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-joyride', get_template_directory_uri() . '/js/foundation.joyride.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-magellan', get_template_directory_uri() . '/js/foundation.magellan.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-orbit', get_template_directory_uri() . '/js/foundation.orbit.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-placeholder', get_template_directory_uri() . '/js/foundation.placeholder.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-reveal', get_template_directory_uri() . '/js/foundation.reveal.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-section', get_template_directory_uri() . '/js/foundation.section.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-tooltips', get_template_directory_uri() . '/js/foundation.tooltips.js', array('foundation-core') );
// wp_enqueue_script( 'foundation-topbar', get_template_directory_uri() . '/js/foundation.topbar.js', array('foundation-core') );
// Now load the child theme js
wp_enqueue_script( 'foundation-app', get_stylesheet_directory_uri() . '/js/app.js', array('foundation-min') );
}
endif;
add_action( 'wp_enqueue_scripts', 'cogito_wp_admin_enqueue_scripts' );
// Disable WordPress version reporting as a basic protection against automatic attacks
function remove_generators() {
return '';
}
add_filter( 'the_generator','remove_generators' );
/**
* Display navigation to next/previous pages when applicable (borrowed from TwentyEleven)
*/
if ( ! function_exists( 'cogito_wp_content_nav' ) ) :
function cogito_wp_content_nav( $nav_id ) {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="<?php echo $nav_id; ?>">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'cogito_wp' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'cogito_wp' ) ); ?></div>
</nav><!-- #nav-above -->
<?php endif;
}
endif;
/**
* Helper function to spell out numbers
* We use this for Foundation classes
*/
function cogito_foundation_sizer($num){
$nums = Array ("denada", "one","two", "three","four","five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
return $nums[$num];
}
/**
* Register menu regions
*
*/
if ( ! function_exists( 'cogito_wp_menu_init' ) ) :
function cogito_wp_menu_init() {
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'desktop-nav', __( 'Primary Menu', 'cogito_wp' ) );
register_nav_menu( 'mobile', __( 'Primary Menu (mobile)', 'cogito_wp' ) );
}
endif;
add_action( 'after_setup_theme', 'cogito_wp_menu_init' );
/**
* Register our sidebars and widgetized areas. Also register the main menu as a dynamic menu
*
*/
if ( ! function_exists( 'cogito_wp_widgets_init' ) ) :
function cogito_wp_widgets_init() {
register_sidebar( array(
'name' => __( 'Left Sidebar', 'cogito_wp' ),
'id' => 'sidebar-left',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Right Sidebar', 'cogito_wp' ),
'id' => 'sidebar-right',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
//Dynamically gererate footer column widget regions
$cogito_init = get_option( 'cogito_init' );
$footers = isset($cogito_init) && isset($cogito_init['footers']) && is_array($cogito_init['footers']) ? $cogito_init['footers'] : array(4,4,4);
if (is_array($footers) && !empty($footers)){
for ($i = 1; $i<= sizeof($footers); $i++){
register_sidebar( array(
'name' => __( 'Footer Area '. ucwords(cogito_foundation_sizer($i)) , 'cogito_wp' ),
'id' => 'footer-'. $i,
'description' => __( 'An optional widget area for your site footer', 'cogito_wp' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
}
// The following lets us define a function in the child theme
// That adds/changes or overwrites anything here.
if ( function_exists( 'cogito_extra_sidebars' ) ){
cogito_extra_sidebars();
}
}
endif;
add_action( 'widgets_init', 'cogito_wp_widgets_init' );
/**
* Sets the post excerpt length to 40 words.
*
* To override this length in a child theme, remove the filter and add your own
* function tied to the excerpt_length filter hook.
*/
if ( ! function_exists( 'cogito_wp_excerpt_length' ) ) :
function cogito_wp_excerpt_length( $length ) {
return 40;
}
endif;
add_filter( 'excerpt_length', 'cogito_wp_excerpt_length' );
/**
* Get Only active Footers
*
* Set the widths of footer regions to space equally. Maximum of 4 regions possible
*
*/
function cogito_get_footers() {
//Dynamically gererate footer column widget regions
$cogito_init = get_option('cogito_init');
$footers = isset($cogito_init) && isset($cogito_init['footers']) && is_array($cogito_init['footers']) ? $cogito_init['footers'] : array(4,4,4);
$widget_list = wp_get_sidebars_widgets();
$width_sum = 0;
$last_used = 0;
//First count the widget areas we have and store active footers in an array
$foot_counter = Array();
for ($i=0;$i<=4;$i++){
if ( isset($widget_list['footer-' . ($i+1)]) && !empty($widget_list['footer-' . ($i+1)] ) ){
//If the footer widths array has something useful in it use it. Otherwise 4 is a good number
$width = isset($footers[$i]) ? $footers[$i] : 4;
$foot_counter[$i+1] = $footers[$i];
$width_sum += $footers[$i];
$last_used = $i+1;
}
}
//If they don't add up to $cogito_init['total_columns'] then add space on the end
if ($width_sum < $cogito_init['total_columns'] && $last_used > 0){
$foot_counter[$last_used] = $cogito_init['total_columns'] - $width_sum + $foot_counter[$last_used];
}
//Now print a block array
if ( $last_used > 0 ){
foreach ($foot_counter as $key=>$footer_width){
print '<div id="footer-'.$key.'" class="columns large-'. $footer_width .'">';
dynamic_sidebar( 'footer-' . $key );
print '</div>';
}
}
}
/**
* Adds two classes to the array of body classes. (borrowed from twenty_eleven)
* The first is if the site has only had one author with published posts.
* The second is if a singular post being displayed
*
* @since Twenty Eleven 1.0
*/
if ( ! function_exists( 'cogito_wp_body_classes' ) ) :
function cogito_wp_body_classes( $classes ) {
if ( function_exists('is_multi_author') && ! is_multi_author() ) {
$classes[] = 'single-author';
}
if ( is_singular() && ! is_home() )
$classes[] = 'singular';
return $classes;
}
endif;
add_filter( 'body_class', 'cogito_wp_body_classes' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts. (borrowed from twenty_eleven)
*
* To override this link in a child theme, remove the filter and add your own
* function tied to the get_the_excerpt filter hook.
*/
if ( ! function_exists( 'cogito_wp_custom_excerpt_more' ) ) :
function cogito_wp_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= cogito_wp_continue_reading_link();
}
return $output;
}
endif;
add_filter( 'get_the_excerpt', 'cogito_wp_custom_excerpt_more' );
/**
* Returns a "Continue Reading" link for excerpts
*/
if ( ! function_exists( 'cogito_wp_continue_reading_link' ) ) :
function cogito_wp_continue_reading_link() {
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'cogito_wp' ) . '</a>';
}
endif;
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link().
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*/
if ( ! function_exists( 'cogito_wp_auto_excerpt_more' ) ) :
function cogito_wp_auto_excerpt_more( $more ) {
return ' …' . cogito_wp_continue_reading_link();
}
endif;
add_filter( 'excerpt_more', 'cogito_wp_auto_excerpt_more' );
/**
* Template for comments and pingbacks. (borrowed from twenty_eleven)
*
* To override this walker in a child theme without modifying the comments template
* simply create your own cogito_wp_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Twenty Eleven 1.0
*/
if ( ! function_exists( 'cogito_wp_comment' ) ) :
function cogito_wp_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'cogito_wp' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'cogito_wp' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<?php cogito_action_comment_top(); ?>
<footer class="comment-meta">
<div class="comment-author vcard">
<?php
$avatar_size = 68;
if ( '0' != $comment->comment_parent )
$avatar_size = 39;
echo get_avatar( $comment, $avatar_size );
/* translators: 1: comment author, 2: date and time */
printf( __( '%1$s on %2$s <span class="says">said:</span>', 'cogito_wp' ),
sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s at %2$s', 'cogito_wp' ), get_comment_date(), get_comment_time() )
)
);
?>
<?php edit_comment_link( __( 'Edit', 'cogito_wp' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'cogito_wp' ); ?></em>
<br />
<?php endif; ?>
</footer>
<div class="comment-content"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>↓</span>', 'cogito_wp' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<?php cogito_action_comment_bottom(); ?>
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // ends check for twentyeleven_comment()
// Custom Pagination (borrowed from wp_foundation)
/**
* Retrieve or display pagination code.
*
* The defaults for overwriting are:
* 'page' - Default is null (int). The current page. This function will
* automatically determine the value.
* 'pages' - Default is null (int). The total number of pages. This function will
* automatically determine the value.
* 'range' - Default is 3 (int). The number of page links to show before and after
* the current page.
* 'gap' - Default is 3 (int). The minimum number of pages before a gap is
* replaced with ellipses (...).
* 'anchor' - Default is 1 (int). The number of links to always show at beginning
* and end of pagination
* 'before' - Default is '<div class="emm-paginate">' (string). The html or text
* to add before the pagination links.
* 'after' - Default is '</div>' (string). The html or text to add after the
* pagination links.
* 'next_page' - Default is '__('»')' (string). The text to use for the
* next page link.
* 'previous_page' - Default is '__('«')' (string). The text to use for the
* previous page link.
* 'echo' - Default is 1 (int). To return the code instead of echo'ing, set this
* to 0 (zero).
*
* @author Eric Martin <eric@ericmmartin.com>
* @copyright Copyright (c) 2009, Eric Martin
* @version 1.0
*
* @param array|string $args Optional. Override default arguments.
* @return string HTML content, if not displaying.
*/
if ( ! function_exists( 'emm_paginate' ) ) :
function emm_paginate($args = null) {
$defaults = array(
'page' => null, 'pages' => null,
'range' => 3, 'gap' => 3, 'anchor' => 1,
'before' => '<div class="row cogito_paginate"><ul class="pagination">', 'after' => '</ul></div>',
'title' => __('<li class="unavailable"></li>'),
'nextpage' => __('»'), 'previouspage' => __('«'),
'echo' => 1
);
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
// print_r($r);
if (!$page && !$pages) {
global $wp_query;
$page = get_query_var('paged');
$page = !empty($page) ? intval($page) : 1;
$posts_per_page = get_query_var('posts_per_page');
$posts_per_page = $posts_per_page > 0 ? $posts_per_page : 1;
$pages = intval(ceil($wp_query->found_posts / $posts_per_page));
}
$output = "";
if ($pages > 1) {
$output .= "$before<li>$title</li>";
$ellipsis = "<li class='unavailable'>...</li>";
if ($page > 1 && !empty($previouspage)) {
$output .= "<li><a href='" . get_pagenum_link($page - 1) . "'>$previouspage</a></li>";
}
$min_links = $range * 2 + 1;
$block_min = min($page - $range, $pages - $min_links);
$block_high = max($page + $range, $min_links);
$left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
$right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
if ($left_gap && !$right_gap) {
$output .= sprintf('%s%s%s',
emm_paginate_loop(1, $anchor),
$ellipsis,
emm_paginate_loop($block_min, $pages, $page)
);
}
else if ($left_gap && $right_gap) {
$output .= sprintf('%s%s%s%s%s',
emm_paginate_loop(1, $anchor),
$ellipsis,
emm_paginate_loop($block_min, $block_high, $page),
$ellipsis,
emm_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else if ($right_gap && !$left_gap) {
$output .= sprintf('%s%s%s',
emm_paginate_loop(1, $block_high, $page),
$ellipsis,
emm_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else {
$output .= emm_paginate_loop(1, $pages, $page);
}
if ($page < $pages && !empty($nextpage)) {
$output .= "<li><a href='" . get_pagenum_link($page + 1) . "'>$nextpage</a></li>";
}
$output .= $after;
}
if ($echo) {
echo $output;
}
return $output;
}
endif;
/**
* Helper function for pagination which builds the page links. (borrowed from wp_foundation)
*
* @access private
*
* @author Eric Martin <eric@ericmmartin.com>
* @copyright Copyright (c) 2009, Eric Martin
* @version 1.0
*
* @param int $start The first link page.
* @param int $max The last link page.
* @return int $page Optional, default is 0. The current page.
*/
function emm_paginate_loop($start, $max, $page = 0) {
$output = "";
for ($i = $start; $i <= $max; $i++) {
$output .= ($page === intval($i))
? "<li class='current'><a href='#'>$i</a></li>"
: "<li><a href='" . get_pagenum_link($i) . "'>$i</a></li>";
}
return $output;
}
/**
* Find a file by first looking in the child theme then in the parent
*
* @param int $filepath should be relative to the theme directory and include a slash.
*
*/
function cogito_get_file_uri(array $filepaths){
$root_wp = getcwd();
// Cache path to theme for duration of this function:
$cogito_dir = get_template_directory();
$cogito_uri = get_template_directory_uri();
$child_dir = get_stylesheet_directory();
$child_uri = get_stylesheet_directory_uri();
foreach ($filepaths as $filepath){
if ( is_file( $child_dir . $filepath) ){
return $child_uri . $filepath;
}
}
//Now do it all again only this time in the parent directory
foreach ($filepaths as $filepath){
if( is_file( $cogito_dir . $filepath) ){
return $cogito_uri . $filepath;
}
}
return false;
}
/**
* Get and place all the icons necesssary (like favicon and apple-touch icons etc).
*
*/
function cogito_get_icons(){
$favicon = cogito_get_file_uri(array('/images/icons/favicon.ico'));
//Update to use sizes from icongen.com
$sizes = array(57,60,72,114,120,144,152);
foreach ($sizes as $size) {
$file = cogito_get_file_uri(array("/images/icons/apple-touch-icon-".$size."x".$size.".png"));
print $file ? '<link rel="apple-touch-icon" href="'.$file.'">' : "";
}
print $favicon ? '<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="' . $favicon .'">' : "";
}
/**
* Test for logo.png in the places we expect to find it.
*
*
* @return string $logo path to logo if found. False if otherwise.
*/
function cogito_get_logo(){
//TODO: work in uploading a logo in the admin interface.
if ($logo = cogito_get_file_uri( array('/images/logo.png', '/logo.png') )){
return $logo;
}
else{
return false;
}
}
/*
https://gist.github.com/awshout/3943026
*/
if ( ! function_exists( 'desktop_nav' ) ) :
function desktop_nav() {
wp_nav_menu(array(
'container' => false, // remove nav container
'container_class' => 'menu', // class of container
'menu' => '', // menu name
'menu_class' => 'top-bar-menu left', // adding custom nav class
'theme_location' => 'desktop-nav', // where it's located in the theme
'before' => '', // before each link <a>
'after' => '', // after each link </a>
'link_before' => '', // before each link text
'link_after' => '', // after each link text
'depth' => 5, // limit the depth of the nav
'fallback_cb' => false, // fallback function (see below)
'walker' => new top_bar_walker()
));
} // end left top bar
endif;
/*
https://gist.github.com/awshout/3943026
Customize the output of menus for Foundation top bar classes
*/
class top_bar_walker extends Walker_Nav_Menu {
function display_element($element, &$children_elements, $max_depth, $depth=0, $args, &$output) {
$element->has_children = !empty($children_elements[$element->ID]);
$element->classes[] = ($element->current || $element->current_item_ancestor) ? 'active' : '';
$element->classes[] = ($element->has_children) ? 'has-dropdown' : '';
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
function start_el(&$output, $item, $depth, $args) {
$item_html = '';
parent::start_el($item_html, $item, $depth, $args);
$output .= ($depth == 0) ? '<li class="divider"></li>' : '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
if(in_array('label', $classes)) {
$output .= '<li class="divider"></li>';
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html);
}
if ( in_array('divider', $classes) ) {
$item_html = preg_replace( '/<a[^>]*>( .* )<\/a>/iU', '', $item_html );
}
$output .= $item_html;
}
function start_lvl(&$output, $depth = 0, $args = array()) {
$output .= "\n<ul class=\"sub-menu dropdown\">\n";
}
} // end top bar walker