-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
executable file
·283 lines (231 loc) · 8.14 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
<?php
/**
* Content Width
*
* Using this feature you can set the maximum allowed width for any content
* in the theme, like oEmbeds and images added to posts.
*/
if ( ! isset( $content_width ) )
$content_width = 620;
/**
* Custom Nav Menus
*/
register_nav_menus( array(
'head' => 'Header Menu',
'foot' => 'Footer Menu'
) );
/**
* Featured Images
*/
add_theme_support('post-thumbnails' );
add_image_size('hard', 980, 400, true );
add_image_size('flex', 560, 999 );
/**
* Feed Links
*/
add_theme_support( 'automatic-feed-links' );
/**
* Widgetized Sections
*/
function base_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'base' ),
'before_title' => '<h3>',
'after_title' => '</h3>',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
) );
register_sidebar( array(
'name' => __( 'Footer', 'base' ),
'before_title' => '<h3>',
'after_title' => '</h3>',
'before_widget' => '<div id="%1$s" class="footget %2$s">',
'after_widget' => '</div>',
) );
}
add_action( 'widgets_init', 'base_widgets_init' );
function scripts_and_styles() {
if( is_singular() && comments_open() )
wp_enqueue_style('comment-style', get_template_directory_uri() . '/css/comments.css');
//wp_enqueue_script('jquery');
//wp_enqueue_script('cform', get_template_directory_uri() . '/js/cform.js', array('jquery'), NULL );
//wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'));
}
add_action('wp_enqueue_scripts', 'scripts_and_styles');
function columns_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'no' => '1/3',
), $atts ) );
list( $no, $all ) = explode( '/', $no );
if( $all % 2 == 0 ) $class = 'two';
if( $all % 3 == 0 ) $class = 'three';
if( $all % 4 == 0 ) $class = 'four';
if( $all % 5 == 0 ) $class = 'five';
if( $all % 6 == 0 ) $class = 'six';
if( $no == 1 )
$col = '<div class="cols"><div class="col col-'. $no .' '. $class .' first">' . $content . '</div>';
elseif( $no > 1 && $no != $all )
$col = '<div class="col col-'. $no .' '. $class .'">' . $content . '</div>';
else
$col = '<div class="col col-'. $no .' '. $class .' last">' . $content . '</div></div>';
return $col;
}
add_shortcode( 'column', 'columns_shortcode' );
/**
* Is Ajax?
* Check if it is an ajax request
*/
function is_ajax() {
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}
/**
* Shorten
* Get part of the content by defining the number of characters.
*
* @author: Baki Goxhaj
* @author URI: http://www.wplancer.com/
*
* @param int $len Required. Number of characters to show
* @param string $str Optional, default is empty. Full text to be shortened.
* @param string $more Optional. Read more link text.
* @param bool $cut Optional, default is true. Remove half-cut words from the shortened text.
* @return string HTML content.
*/
function shorten( $len, $str = '', $more = 'Read more →', $cut = true ) {
if( $str == '' ) $str = get_the_content();
$str = strip_tags( strip_shortcodes( $str ) );
$read = '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . $more . '</a>';
if( strlen( $str ) <= $len )
echo $str;
else
echo ( $cut ? substr( $str, 0, strrpos( substr( $str, 0, $len ), ' ' ) ) : substr( $str, 0, $len ) ) . '... ' . $read;
}
/**
* Get First Paragraph
*
* @return string
*/
function get_first_paragraph( $str ) {
$str = substr( $str, 0, strpos( $str, "</p>") + 4 );
$str = str_replace( "<p>", "", str_replace( "<p/>", "", $str ) );
return $str;
}
/**
* The Breadcrumb
* Adds a simple but highly customizable breadcrumb to your WordPress website
* @author: Baki Goxhaj of WPlancer.Com
*/
function the_breadcrumb( $sep = ' / ' ) {
$out = '<a href="'. home_url() .'">Home</a>';
if( is_category() )
$out .= $sep . single_cat_title( '', false );
if( is_single() )
$out .= $sep . get_the_category_list( $sep, 'multiple') . $sep . single_post_title( '', false );
if( is_page() )
$out .= $sep . single_post_title( '', false );
if( is_singular('event') )
$out .= $sep . '<a href="' . get_permalink(371) . '">Events</a>' . $sep . single_post_title( '', false );
if( is_search() )
$out .= $sep . 'Search results for "' . get_search_query() . '"';
if( is_author() )
$out .= $sep . 'All posts by ' . get_the_author_meta( 'display_name', get_query_var('author') );
echo $out;
}
function the_location() {
global $post;
if( is_archive() )
$where = 'Browsing Website <em>Archive</em>';
if( is_category() )
$where = 'Browsing <em>' . single_cat_title('', false) . '</em> Category';
if( is_tag() )
$where = 'Browsing <em>' . single_tag_title('', false) . '</em> Tag';
if( is_tax() )
$where = 'Browsing <em>' . single_term_title('', false) . '</em> Archive';
if( is_author() )
$where = 'Browsing all posts by <em>' . get_the_author_meta( 'display_name', get_query_var('author') ) . '</em>' ;
if( is_search() )
$where = 'Browsing <em>' . get_search_query() . '</em> Search Results';
if( is_404() )
$where = 'Nothing Found - <em>Sorry!<em>';
echo $where;
}
/**
* The pagination function
*/
function the_pagination(){
global $wp_query;
$big = 999999999; // need an unlikely integer
$nav = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
echo '<div class="pagination">', $nav, '</div>';
}
/**
* Update Contact Fields
*/
function base_contact_methods( $contactmethods ) {
// Remove we what we don't want
unset( $contactmethods['aim'] );
unset( $contactmethods['yim'] );
unset( $contactmethods['jabber'] );
// Add some useful ones
$contactmethods['twitter'] = 'Twitter Username';
$contactmethods['facebook'] = 'Facebook Profile URL';
$contactmethods['linkedin'] = 'LinkedIn Public Profile URL';
$contactmethods['googleplus'] = 'Google+ Profile URL';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'base_contact_methods' );
if ( ! function_exists( 'base_comments' ) ) :
function base_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'base' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'base' ), '<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">
<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>', 'base' ),
sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
sprintf( '<a href="%1$s"><time 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', 'base' ), get_comment_date(), get_comment_time() )
)
);
?>
<?php edit_comment_link( __( 'Edit', 'base' ), '<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.', 'base' ); ?></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>', 'base' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // ends check for base_comments()