1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Auto Load Next Post Core Functions |
4
|
|
|
* |
5
|
|
|
* General core functions available for both the front-end and admin. |
6
|
|
|
* |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
* @version 1.4.8 |
9
|
|
|
* @author Sébastien Dumont |
10
|
|
|
* @category Core |
11
|
|
|
* @package Auto Load Next Post |
12
|
|
|
* @license GPL-2.0+ |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
if ( ! defined('ABSPATH')) { |
16
|
|
|
exit; // Exit if accessed directly. |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// Include core functions |
20
|
|
|
include('auto-load-next-post-conditional-functions.php'); |
21
|
|
|
include('auto-load-next-post-formatting-functions.php'); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* When the 'partial' endpoint is used on a post, retrieve only the post content. |
25
|
|
|
*/ |
26
|
|
|
function auto_load_next_post_template_redirect() { |
27
|
|
|
global $wp_query; |
28
|
|
|
|
29
|
|
|
// If this is not a request for partial or a singular object then bail |
30
|
|
|
if ( ! isset($wp_query->query_vars['partial']) || ! is_singular()) { |
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Load the template file from the theme (child or main) if one exists. |
36
|
|
|
* If theme does not have a template file for Auto Load Next Post, |
37
|
|
|
* the plugin will load a default template. |
38
|
|
|
*/ |
39
|
|
|
$child_path = get_stylesheet_directory() . '/' . AUTO_LOAD_NEXT_POST_TEMPLATE_PATH; |
40
|
|
|
$template_path = get_template_directory() . '/' . AUTO_LOAD_NEXT_POST_TEMPLATE_PATH; |
41
|
|
|
$default_path = AUTO_LOAD_NEXT_POST_FILE_PATH; |
42
|
|
|
|
43
|
|
|
if ( file_exists( $child_path . 'content-partial.php' ) ) { |
44
|
|
|
include( $child_path . 'content-partial.php' ); |
45
|
|
|
} |
46
|
|
|
else if( file_exists( $template_path . 'content-partial.php') ) { |
47
|
|
|
include( $template_path . 'content-partial.php' ); |
48
|
|
|
} |
49
|
|
|
else if( file_exists( $default_path . '/template/content-partial.php' ) ) { |
50
|
|
|
include( $default_path . '/template/content-partial.php' ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
exit; |
54
|
|
|
} |
55
|
|
|
add_action('template_redirect', 'auto_load_next_post_template_redirect'); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Adds the comments template after the post content. |
59
|
|
|
* |
60
|
|
|
* @since 1.4.8 |
61
|
|
|
*/ |
62
|
|
|
function auto_load_next_post_comments() { |
63
|
|
|
// If comments are open or we have at least one comment, load up the comment template. |
64
|
|
|
if ( comments_open() || get_comments_number() ) : |
65
|
|
|
comments_template(); |
66
|
|
|
endif; |
67
|
|
|
} |
68
|
|
|
add_action('alnp_load_after_content', 'auto_load_next_post_comments', 1, 5); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Adds the post navigation for the previous link only after the post content. |
72
|
|
|
* |
73
|
|
|
* @since 1.4.8 |
74
|
|
|
*/ |
75
|
|
|
function auto_load_next_post_navigation() { |
76
|
|
|
?> |
77
|
|
|
<nav class="navigation post-navigation" role="navigation"> |
78
|
|
|
<span class="nav-previous"><?php previous_post_link('%link', '<span class="meta-nav">'._x('←', 'Previous post link', 'auto-load-next-post').'</span> %title'); ?></span> |
79
|
|
|
</nav> |
80
|
|
|
<?php |
81
|
|
|
} |
82
|
|
|
add_action('alnp_load_after_content', 'auto_load_next_post_navigation', 1, 10); |
83
|
|
|
|