-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
303 lines (254 loc) · 10.3 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
<?php
// =========================
// = Initiate widget areas =
// =========================
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=>'Sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="sidebar-left">',
'after_title' => '</h3>',
));
}
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=>'Bottom 1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="sidebar-bottom">',
'after_title' => '</h3>',
));
}
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=>'Bottom 2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="sidebar-bottom">',
'after_title' => '</h3>',
));
}
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=>'Bottom 3',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="sidebar-bottom">',
'after_title' => '</h3>',
));
}
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=>'Bottom 4',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="sidebar-bottom">',
'after_title' => '</h3>',
));
}
update_option('posts_per_page', 7); // Posts per page
// ====================================
// = WordPress 2.9+ Thumbnail Support =
// ====================================
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 155, 110, true ); // 305 pixels wide by 380 pixels tall, set last parameter to true for hard crop mode
add_image_size( 'one', 155, 110, true ); // Set thumbnail size
add_image_size( 'two', 350, 248, true ); // Set thumbnail size
add_image_size( 'big', 546, 387, true ); // Set thumbnail size
// ===========================
// = WordPress 3.0+ Nav Menu =
// ===========================
register_nav_menus(
array(
'custom-menu'=>__('Sephia menu'),
)
);
function custom_menu(){
wp_list_pages('title_li=&depth=1');
}
// ==================================
// = WP 3.0 Custom Background Setup =
// ==================================
if ( function_exists( 'add_custom_background' ) )
{ add_custom_background(); }
// ========================
// = Display latest tweet =
// ========================
function displayLatestTweet($demianpeeters){
include_once(ABSPATH.WPINC.'/rss.php');
$latest_tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $demianpeeters . "&rpp=3");
echo $latest_tweet->items[0]['atom_content'];
}
// ==============
// = Get TinyUrl =
// ==============
function getTinyUrl($url) {
$tinyurl = @file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
return $tinyurl;
}
// ==============
// = Word Count =
// ==============
function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
}
// =========================
// = Change excerpt lenght =
// =========================
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
return 35; }
// =================================
// = Change default excerpt symbol =
// =================================
function suburbia_excerpt($text) { return str_replace('[...]', '...', $text); } add_filter('the_excerpt', 'suburbia_excerpt');
// =================================
// = Add comment callback function =
// =================================
function suburbia_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>" class="clear">
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta">
<?php printf(__('<span class="fn">%s</span>'), get_comment_author_link()) ?>
<div class="comment-date"><?php printf(__('%1$s'), get_comment_date()) ?></div>
<?php echo get_avatar( $comment , $size='55' ); ?>
</div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php
} ?>
<?php
// ====================
// = Add options page =
// ====================
function themeoptions_admin_menu()
{
// here's where we add our theme options page link to the dashboard sidebar
add_theme_page("Theme Options", "Theme Options", 'edit_themes', basename(__FILE__), 'themeoptions_page');
}
function themeoptions_page()
{
if ( $_POST['update_themeoptions'] == 'true' ) { themeoptions_update(); } //check options update
// here's the main function that will generate our options page
?>
<div class="wrap">
<div id="icon-themes" class="icon32"><br /></div>
<h2>SUBURBIA Theme Options</h2>
<form method="POST" action="">
<input type="hidden" name="update_themeoptions" value="true" />
<h3>Your social links</h3>
<table width="90%" border="0">
<tr>
<td valign="top" width="50%"><p><label for="fbkurl"><strong>Facebook URL</strong></label><br /><input type="text" name="fbkurl" id="fbkurl" size="32" value="<?php echo get_option('suburbia_fbkurl'); ?>"/></p><p><small><strong>example:</strong><br /><em>http://www.facebook.com/wpshower</em></small></p></td>
<td valign="top"width="50%"><p><label for="twturl"><strong>Twitter URL</strong></label><br /><input type="text" name="twturl" id="twturl" size="32" value="<?php echo get_option('suburbia_twturl'); ?>"/></p><p><small><strong>example:</strong><br /><em>http://twitter.com/wpshower</em></small></p>
</td>
</tr>
</table>
<h3>Custom logo</h3>
<table width="90%" border="0">
<tr>
<td valign="top" width="50%"><p><label for="custom_logo"><strong>URL to your custom logo</strong></label><br /><input type="text" name="custom_logo" id="custom_logo" size="32" value="<?php echo get_option('suburbia_custom_logo'); ?>"/></p><p><small><strong>Usage:</strong><br /><em><a href="<?php bloginfo("url"); ?>/wp-admin/media-new.php">Upload your logo</a> (246 x 35px) using WordPress Media Library and insert its URL here</em></small></p></td>
<td valign="top"width="50%"><p>
<?php
ob_start();
ob_implicit_flush(0);
echo get_option('suburbia_custom_logo');
$my_logo = ob_get_contents();
ob_end_clean();
if (
$my_logo == ''
): ?>
<a href="<?php bloginfo("url"); ?>/">
<img src="<?php bloginfo('template_url'); ?>/images/logo.png" alt="<?php bloginfo('name'); ?>"></a>
<?php else: ?>
<a href="<?php bloginfo("url"); ?>/"><img src="<?php echo get_option('suburbia_custom_logo'); ?>"></a>
<?php endif ?>
</p>
</td>
</tr>
</table>
<h3>Ápropos</h3>
<table width="90%" border="0">
<tr>
<td valign="top" width="50%"><p><label for="apropos"><strong>URL to your custom logo</strong></label><br /><input type="text" name="apropos" id="apropos" size="32" value="<?php echo get_option('suburbia_apropos'); ?>"/></p><p><small><strong>Usage:</strong><br /><em><a href="<?php bloginfo("url"); ?>/wp-admin/media-new.php">Upload your logo</a> (155 x 155px) using WordPress Media Library and insert its URL here</em></small></p></td>
<td valign="top"width="50%"><p>
<?php
ob_start();
ob_implicit_flush(0);
echo get_option('suburbia_apropos');
$my_logo = ob_get_contents();
ob_end_clean();
if (
$my_logo == ''
): ?>
<a href="<?php bloginfo("url"); ?>/">
<img src="<?php bloginfo('template_url'); ?>/images/logo2.gif" alt="<?php bloginfo('name'); ?>"></a>
<?php else: ?>
<a href="<?php bloginfo("url"); ?>/"><img src="<?php echo get_option('suburbia_apropos'); ?>"></a>
<?php endif ?>
</p>
</td>
</tr>
</table>
<h3>Advanced options</h3>
<table width="90%" border="0">
<tr>
<td valign="top" width="50%"><p><label for="twtun"><strong>Twitter username</strong></label><br /><input type="text" name="twtun" id="twtun" size="32" value="<?php echo get_option('suburbia_twtun'); ?>"/><p><small><strong>Example: </strong><em>wpshower</em><br />Your latest tweet will be displayed within the 3rd bottom widget area.</small></p>
</td>
<td valign="top" width="50%"><p><label for="eml"><strong>E-mail</strong></label><br /><input type="text" name="eml" id="eml" size="32" value="<?php echo get_option('suburbia_eml'); ?>"/><p><small><strong>Example: </strong><em>[email protected]</em></small></p>
</td>
</tr>
</table>
<p><input type="submit" name="search" value="Update Options" class="button button-primary" /></p>
</form>
</div>
<?php
}
add_action('admin_menu', 'themeoptions_admin_menu');
// Update options function
function themeoptions_update()
{
// this is where validation would go
update_option('suburbia_fbkurl', $_POST['fbkurl']);
update_option('suburbia_twturl', $_POST['twturl']);
update_option('suburbia_apropos', $_POST['apropos']);
update_option('suburbia_custom_logo', $_POST['custom_logo']);
update_option('suburbia_twtun', $_POST['twtun']);
update_option('suburbia_eml', $_POST['eml']);
}
function n_posts_link_attributes(){
return 'class="nextpostslink"';
}
function p_posts_link_attributes(){
return 'class="previouspostslink"';
}
add_filter('next_posts_link_attributes', 'n_posts_link_attributes');
add_filter('previous_posts_link_attributes', 'p_posts_link_attributes');
function custom_excerpt($string, $limit) {
$words = explode(" ",$string);
if ( count($words) >= $limit) $dots = '...';;
echo implode(" ",array_splice($words,0,$limit)).$dots;
}
function commentdata_fix($commentdata) {
if ( $commentdata['comment_author_url'] == 'Website') {
$commentdata['comment_author_url'] = '';
}
if ($commentdata['comment_content'] == 'Comment') {
$commentdata['comment_content'] = '';
}
return $commentdata;
}
add_filter('preprocess_comment','commentdata_fix');
?>