-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoxygen_previous_and_next_post_handling.php
More file actions
40 lines (40 loc) · 1.98 KB
/
oxygen_previous_and_next_post_handling.php
File metadata and controls
40 lines (40 loc) · 1.98 KB
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
<?php
/*previous and next post URL's */
function o2_get_previous_post_permalink($same_cat=false, $excl='',$tax='category'){
$p=get_previous_post($same_cat, $excl, $tax);
return $p ? get_permalink($p->ID) : null;
}
function o2_get_next_post_permalink($same_cat=false, $excl=array(),$tax='category'){
$p=get_next_post($same_cat, $excl, $tax);
return $p ? get_permalink($p->ID) : null;
}
/*previous and next post titles */
function o2_get_previous_post_title($same_cat=false, $excl=array(),$tax='category'){
$p = get_previous_post($same_cat, $excl, $tax)->post_title;
return $p ? apply_filters( 'the_title', $p) : null;
}
function o2_get_next_post_title($same_cat=false, $excl=array(),$tax='category'){
$p = get_next_post($same_cat, $excl, $tax)->post_title;
return $p ? apply_filters( 'the_title', $p) : null;
}
/* some oxy conditions for checking for sibling posts */
if( function_exists('oxygen_vsb_register_condition') ) {
oxygen_vsb_register_condition('Next post published', array('options'=>array('true', 'false'), 'custom'=>false), array('=='), 'cb_next_post_exists', 'Post');
oxygen_vsb_register_condition('Previous post published', array('options'=>array('true', 'false'), 'custom'=>false), array('=='), 'cb_previous_post_exists', 'Post');
oxygen_vsb_register_condition('Next in Category published', array('options'=>array('true', 'false'), 'custom'=>false), array('=='), 'cb_cat_has_next_post', 'Post');
oxygen_vsb_register_condition('Previous in Category published', array('options'=>array('true', 'false'), 'custom'=>false), array('=='), 'cb_cat_has_prev_post', 'Post');
}
/* callbacks for oxygen conditions */
function cb_next_post_exists($v){
return ($v === 'true') === boolval(get_next_post());
}
function cb_previous_post_exists($v){
return ($v === 'true') === boolval(get_previous_post());
}
function cb_cat_has_next_post($v){
return ($v === 'true') === boolval(get_next_post(1));
}
function cb_cat_has_previous_post($v){
return ($v === 'true') === boolval(get_previous_post(1));
}
?>