-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
332 lines (259 loc) · 11.7 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
<?php
/**
* @package WordPress
* @subpackage APOD-Wordpress-Theme
* @since HTML5 Reset 2.0
*/
// Options Framework (https://github.com/devinsays/options-framework-plugin)
if ( !function_exists( 'optionsframework_init' ) ) {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/_/inc/' );
require_once dirname( __FILE__ ) . '/_/inc/options-framework.php';
}
// Theme Setup (based on twentythirteen: http://make.wordpress.org/core/tag/twentythirteen/)
function APOD_setup() {
load_theme_textdomain( 'APOD', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'structured-post-formats', array( 'link' ) );
add_theme_support( 'post-formats', array( 'image', 'video' ) );
register_nav_menu( 'primary', __( 'Navigation Menu', 'APOD' ) );
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'APOD_setup' );
// Scripts & Styles
// Load jQuery
function my_scripts_method() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', get_template_directory_uri() . '/_/js/jquery-1.9.1.min.js');
wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
function APOD_scripts_styles() {
global $wp_styles;
// Load Comments
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
wp_enqueue_script( 'APOD-Mobile', get_template_directory_uri() . '/_/js/jquery.mobile-1.3.0.min.js' );
wp_enqueue_script( 'APOD-Less', get_template_directory_uri() . '/_/js/less-1.3.3.min.js' );
// Load Stylesheets
//wp_enqueue_style( 'APOD-Mobile-Structure', get_template_directory_uri() . '/css/jquery.mobile.structure-1.3.0.min.css' );
//wp_enqueue_style( 'APOD-Mobile-Grid', get_template_directory_uri() . '/css/jqm.grid.css' );
//wp_enqueue_style( 'APOD-LESS', get_template_directory_uri() . '/less/theme.less' );
}
add_action( 'wp_enqueue_scripts', 'APOD_scripts_styles' );
// WP Title (based on twentythirteen: http://make.wordpress.org/core/tag/twentythirteen/)
function APOD_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
// Add the site name.
$title .= get_bloginfo( 'name' );
//Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
//Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'APOD' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'APOD_wp_title', 10, 2 );
//OLD STUFF BELOW
// Clean up the <head>
function removeHeadLinks() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
}
add_action('init', 'removeHeadLinks');
// Custom Menu
register_nav_menu( 'primary', __( 'Navigation Menu', 'APOD' ) );
// Widgets
function APOD_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar Widgets', 'APOD' ),
'id' => 'sidebar-primary',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'APOD_widgets_init' );
// APOD NEXT/PREV APOD NEXT/PREV APOD NEXT/PREV APOD NEXT/PREV APOD NEXT/PREV APOD NEXT/PREV
// Filter previous_post_link and next_post_link for APODS
function filter_next_post_link($link) {
global $post;
$post = get_post($post_id);
$next_post = get_next_post();
$title = mysql2date('d F Y', $next_post->post_date, false);
$link = str_replace("rel=", 'title="Click to view next APOD" data-role="button" data-transition="fade" data-ajax="true" data-dom-cache="true" data-theme="c" data-icon="arrow-r" data-iconpos="right" rel=', $link);
return $link;
}
add_filter('next_post_link', 'filter_next_post_link');
function filter_previous_post_link($link) {
global $post;
$post = get_post($post_id);
$previous_post = get_previous_post();
$title = mysql2date('d F Y', $previous_post->post_date, false);
$link = str_replace("rel=", 'title="Click to view previous APOD" data-role="button" data-transition="fade" data-ajax="true" data-dom-cache="true" data-theme="c" data-icon="arrow-l" rel=', $link);
return $link;
}
add_filter('previous_post_link', 'filter_previous_post_link');
// DESKTOP APOD NAVIGATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function post_navigation() {
global $post;
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
?>
<!-- the buttons! -->
<div class="six column"><?php previous_post_link( '%link', _x( '<span class="offscreen">View previous APOD: </span> %title', 'Previous post link', 'APOD' ) ); ?></div>
<div class="six column"><?php next_post_link( '%link', _x( '<span class="offscreen">View next APOD: </span> %title', 'Next post link', 'APOD' ) ); ?></div>
<?php }
// MOBILE APOD NAVIGATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function post_navigation_mobile() {
global $post;
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
?>
<!-- the buttons! -->
<div class="ui-grid-a">
<div class="ui-block-a"><?php previous_post_link( '%link', _x('Prev', 'APOD' ) ); ?></div>
<div class="ui-block-b"><?php next_post_link( '%link', _x('Next', 'APOD' ) ); ?></div>
</div><!-- /grid-a -->
<?php }
//Navigation Navigation Navigation Navigation Navigation Navigation Navigation Navigation
//main menu
class data_type_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li>';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend = '';
$append = '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes . ' id="menu-item-' . $item->ID . '"' . $value . $class_names .' data-theme="c" title="' . $item->attr_title . '">';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
//sub menu
class data_type_walker_sub extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend = '';
$append = '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes . ' id="menu-item-' . $item->ID . '"' . $value . $class_names .' data-theme="a" title="' . 'Link to ' . $item->title . '">';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
//menu item classes "ui-btn-active ui-state-persist"
function current_to_active($text){
$replace = array(
'current_page_item' => 'ui-btn-active ui-state-persist',
'current_page_parent' => 'ui-btn-active ui-state-persist',
'current_page_ancestor' => 'ui-btn-active ui-state-persist',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter ('wp_nav_menu','current_to_active');
// ARCHIVE ARCHIVE ARCHIVE ARCHIVE ARCHIVE ARCHIVE ARCHIVE ARCHIVE ARCHIVE ARCHIVE
// Make archive big enough for a year.
function number_of_posts_on_archive($query){
if ($query->is_archive) {
$query->set('posts_per_page', 365);
}
return $query;
}
add_filter('pre_get_posts', 'number_of_posts_on_archive');
// Posted On date
function posted_on() {
printf( __( '<span class="sep">Posted </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a> by <span class="byline author vcard">%5$s</span>', '' ),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_author() )
);
}
//filter archive by specific year/month/day
function takien_archive_where($where,$args){
$year = isset($args['year']) ? $args['year'] : '';
if($year){
$where .= " AND YEAR(post_date) = '$year' ";
$where .= $month ? " AND MONTH(post_date) = '$month' " : '';
$where .= $day ? " AND DAY(post_date) = '$day' " : '';
}
return $where;
}
add_filter( 'getarchives_where','takien_archive_where',10,2);
remove_filter('term_description','wpautop');
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
add_action( 'template_redirect', 'redirect' );
function redirect() {
if ( is_home() && ! is_paged() ) :
wp_redirect( get_permalink() , 301 );
exit;
endif;
}
add_action( 'init', 'my_remove_filters_func' );
function my_remove_filters_func() {
remove_filter( 'the_content', 'sharing_display', 19 );
remove_filter( 'the_excerpt', 'sharing_display', 19 );
};
function highlight_search_term($text){
if(is_search()){
$keys = implode('|', explode(' ', get_search_query()));
$text = preg_replace('/(' . $keys .')/iu', '<span class="search-terms">\0</span>', $text);
}
return $text;
}
add_filter('the_excerpt', 'highlight_search_term');
add_filter('the_title', 'highlight_search_term');
?>