-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
218 lines (193 loc) · 7.46 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
<?php
/**
* Understrap functions and definitions
*
* @package understrap
*/
/**
* Initialize theme default settings
*/
require get_template_directory() . '/inc/theme-settings.php';
/**
* Theme setup and custom theme supports.
*/
require get_template_directory() . '/inc/setup.php';
/**
* Register widget area.
*/
require get_template_directory() . '/inc/widgets.php';
/**
* Enqueue scripts and styles.
*/
require get_template_directory() . '/inc/enqueue.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom pagination for this theme.
*/
require get_template_directory() . '/inc/pagination.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Custom Comments file.
*/
require get_template_directory() . '/inc/custom-comments.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Load custom WordPress nav walker.
*/
require get_template_directory() . '/inc/bootstrap-wp-navwalker.php';
/**
* Load WooCommerce functions.
*/
require get_template_directory() . '/inc/woocommerce.php';
/**
* Load Editor functions.
*/
require get_template_directory() . '/inc/editor.php';
/**
* Load Snippets
*/
require get_template_directory() . '/inc/snippets/shortcodes.php';
function penge_adjust_queries($query) {
if (!is_admin() AND is_post_type_archive('event') AND $query->is_main_query()) {
$today = date('Ymd');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key'=> 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
));
}
}
function taxonomy_event_category($query) {
if (!is_admin() AND is_tax('event_category') AND $query->is_main_query()) {
$today = date('Ymd');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key'=> 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
));
}
}
add_action('pre_get_posts', 'penge_adjust_queries');
add_action('pre_get_posts', 'taxonomy_event_category');
function wpse_get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array(), $iscrumb=false ) {
$chain = '';
$parent = get_term( $id, 'category' );
if ( is_wp_error( $parent ) ) {
return $parent;
}
if ( $nicename ) {
$name = $parent->slug;
} else {
$name = $parent->name;
}
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
$visited[] = $parent->parent;
$chain .= wpse_get_category_parents( $parent->parent, $link, $separator, $nicename, $visited , $iscrumb);
}
if (is_rtl()){
$sep_direction ='\\';
} else {
$sep_direction ='/';
}
if ($iscrumb){
$chain .= '<li><span class="sep">'.$sep_direction.'</span><a href="' . esc_url( get_category_link( $parent->term_id ) ) . '"><span>'.$name.'</span></a></li>' . $separator ;
} elseif ( $link && !$iscrumb) {
$chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator ;
} else {
$chain .= $name.$separator;
}
return $chain;
}
function wpse_get_breadcrumbs() {
global $wp_query;
if (is_rtl()){
$sep_direction ='\\';
} else {
$sep_direction ='/ ';
}?>
<div class="nav-breadcrumbs">
<ul class="ml-0"><?php
// Adding the Home Page ?>
<li><a href="<?php echo esc_url( home_url() ); ?>"><span> <?php bloginfo('name'); ?></span></a></li><?php
if ( ! is_front_page() ) {
// Check for categories, archives, search page, single posts, pages, the 404 page, and attachments
if ( is_category() ) {
$cat_obj = $wp_query->get_queried_object();
$thisCat = get_category( $cat_obj->term_id );
$parentCat = get_category( $thisCat->parent );
if($thisCat->parent != 0) {
$cat_parents = wpse_get_category_parents( $parentCat, true, '', false, array(), true );
}
if ( $thisCat->parent != 0 && ! is_wp_error( $cat_parents ) ) {
echo $cat_parents;
}
echo '<li><span class="sep">'.$sep_direction.'</span><a href="'.get_category_link($thisCat).'"><span>'.single_cat_title( '', false ).'</span></a></li>';
} elseif ( is_archive() && ! is_category() ) { ?>
<li><span class="sep"><?php echo $sep_direction;?></span> <?php _e( 'Archives' ); ?></li><?php
} elseif ( is_search() ) { ?>
<li><span class="sep"><?php echo $sep_direction;?></span> <?php _e( 'Search Results' ); ?></li><?php
} elseif ( is_404() ) { ?>
<li><span class="sep"><?php echo $sep_direction;?></span> <?php _e( '404 Not Found' ); ?></li><?php
} elseif ( is_singular() ) {
$category = get_the_category();
$category_id = get_cat_ID( $category[0]->cat_name );
$cat_parents = wpse_get_category_parents( $category_id, true, '',false, array(), true );
if ( ! is_wp_error( $cat_parents ) ) {
echo $cat_parents;
}?>
<li>
<a href="<?php the_permalink();?>"><span class="sep"><?php echo $sep_direction;?></span><?php the_title();?></a>
</li><?php
} elseif ( is_singular( 'attachment' ) ) { ?>
<li>
<span class="sep"><?php echo $sep_direction;?></span> <?php the_title(); ?>
</li><?php
} elseif ( is_page() ) {
$post = $wp_query->get_queried_object();
if ( $post->post_parent == 0 ) { ?>
<li><?php _e( '<span class="sep">/</span>' ); the_title(); ?></li><?php
} else {
$title = the_title( '','', false );
$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
array_push( $ancestors, $post->ID );
foreach ( $ancestors as $ancestor ) {
if ( $ancestor != end( $ancestors ) ) { ?>
<li>
<span class="sep"><?php echo $sep_direction;?></span><a href="<?php echo esc_url( get_permalink( $ancestor ) ); ?>"> <span><?php echo strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ); ?></span></a>
</li><?php
} else { ?>
<li>
<span class="sep"><?php echo $sep_direction;?></span><?php echo strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ); ?>
</li><?php
}
}
}
}
} ?>
</ul></div><?php
}