forked from thewirelessguy/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
323 lines (272 loc) · 9.69 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
<?php
// Disable WordPress version reporting as a basic protection against attacks
function remove_generators() {
return '';
}
add_filter('the_generator','remove_generators');
// This theme supports a variety of post formats.
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
// Add thumbnail support
add_theme_support( 'post-thumbnails' );
// Disable the admin bar, set to true if you want it to be visible.
show_admin_bar(FALSE);
// Shortcodes
include('inc/shortcodes.php');
// Add theme support for Automatic Feed Links
add_theme_support( 'automatic-feed-links' );
// Enqueue CSS and scripts
function load_cornerstone_scripts() {
global $wp_styles;
wp_enqueue_style(
'normalize',
get_template_directory_uri() . '/css/normalize.css',
array(),
'2.1.1',
'all'
);
wp_enqueue_style(
'foundation_css',
get_template_directory_uri() . '/css/foundation.min.css',
array('normalize'),
'4.1.6',
'all'
);
wp_enqueue_style(
'foundation_ie8_grid',
get_template_directory_uri() . '/css/ie8-grid-foundation-4.css',
array( 'foundation_css' ),
'1.0',
'all'
);
$wp_styles->add_data( 'foundation_ie8_grid', 'conditional', 'lt IE 8' );
wp_enqueue_script(
'foundation_modernizr_js',
get_template_directory_uri() . '/js/custom.modernizr.js',
array(),
'2.6.2',
false
);
wp_enqueue_script(
'foundation_js',
get_template_directory_uri() . '/js/foundation.min.js',
array('jquery'),
'4.1.6',
true
);
}
add_action('wp_enqueue_scripts', 'load_cornerstone_scripts',0);
// load Foundation specific functions
require_once('inc/foundation.php');
/**
* Register Navigation Menus
*/
// Register wp_nav_menus
function cornerstone_menus() {
register_nav_menus(
array(
'header-menu-left' => __( 'Header Menu (left)', 'cornerstone' ),
'header-menu-right' => __( 'Header Menu (right)', 'cornerstone' ),
'footer-menu' => __( 'Footer Menu', 'cornerstone' )
)
);
}
add_action( 'init', 'cornerstone_menus' );
// Sidebars
if (function_exists('register_sidebar')) {
// Right Sidebar
register_sidebar(array(
'name'=> 'Right Sidebar',
'id' => 'right_sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
// Footer Sidebar
register_sidebar(array(
'name'=> 'Footer Sidebar',
'id' => 'footer_sidebar',
'before_widget' => '<div id="%1$s" class="large-4 columns %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
// Comments
// Custom callback to list comments in the Foundation style
function custom_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
$GLOBALS['comment_depth'] = $depth;
?>
<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
<div class="comment-author vcard"><?php commenter_link() ?></div>
<div class="comment-meta"><?php printf(__('Posted %1$s at %2$s <span class="meta-sep">|</span> <a href="%3$s" title="Permalink to this comment">Permalink</a>', 'Foundation'),
get_comment_date(),
get_comment_time(),
'#comment-' . get_comment_ID() );
edit_comment_link(__('Edit', 'Foundation'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'Foundation') ?>
<div class="comment-content">
<?php comment_text() ?>
</div>
<?php // echo the comment reply link
if($args['type'] == 'all' || get_comment_type() == 'comment') :
comment_reply_link(array_merge($args, array(
'reply_text' => __('Reply','Foundation'),
'login_text' => __('Log in to reply.','Foundation'),
'depth' => $depth,
'before' => '<div class="comment-reply-link">',
'after' => '</div>'
)));
endif;
?>
<?php } // end custom_comments
// Custom callback to list pings
function custom_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
<div class="comment-author"><?php printf(__('By %1$s on %2$s at %3$s', 'Foundation'),
get_comment_author_link(),
get_comment_date(),
get_comment_time() );
edit_comment_link(__('Edit', 'Foundation'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
<?php if ($comment->comment_approved == '0') _e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'Foundation') ?>
<div class="comment-content">
<?php comment_text() ?>
</div>
<?php } // end custom_pings
// Produces an avatar image with the hCard-compliant photo class
function commenter_link() {
$commenter = get_comment_author_link();
if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
$commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
} else {
$commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
}
$avatar_email = get_comment_author_email();
$avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, 35 ) );
echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
} // end commenter_link
// Custom Pagination
/**
* 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 begining
* 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 <[email protected]>
* @copyright Copyright (c) 2009, Eric Martin
* @version 1.0
*
* @param array|string $args Optional. Override default arguments.
* @return string HTML content, if not displaying.
*/
function emm_paginate($args = null) {
$defaults = array(
'page' => null, 'pages' => null,
'range' => 3, 'gap' => 3, 'anchor' => 1,
'before' => '<ul class="pagination">', 'after' => '</ul>',
'title' => __('<li class="unavailable"></li>'),
'nextpage' => __('»'), 'previouspage' => __('«'),
'echo' => 1
);
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
if (!$page && !$pages) {
global $wp_query;
$page = get_query_var('paged');
$page = !empty($page) ? intval($page) : 1;
$posts_per_page = intval(get_query_var('posts_per_page'));
$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;
}
/**
* Helper function for pagination which builds the page links.
*
* @access private
*
* @author Eric Martin <[email protected]>
* @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;
}
?>