-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathstories.php
More file actions
150 lines (118 loc) · 4.1 KB
/
Copy pathstories.php
File metadata and controls
150 lines (118 loc) · 4.1 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
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
<?php
/**
* Template Name: Stories
*
* Shows a list of all published stories with a statistics block and hooks
* for customization. It's paginated using the "Blog pages show at most"
* (posts_per_page) option under Settings > Reading.
*
* @package WordPress
* @subpackage Fictioneer
* @since 3.0
* @see fictioneer_clause_sticky_stories()
*/
use Fictioneer\Sanitizer;
use Fictioneer\Utils;
// Setup
$post_id = get_the_ID();
$page = Utils::get_global_page(); // Main query
$order = Sanitizer::sanitize_query_var( $_GET['order'] ?? 0, ['desc', 'asc'], 'desc' );
$orderby = Sanitizer::sanitize_query_var( $_GET['orderby'] ?? 0, fictioneer_allowed_orderby(), 'modified' );
$ago = $_GET['ago'] ?? 0;
$ago = is_numeric( $ago ) ? absint( $ago ) : sanitize_text_field( $ago );
// Prepare query
$query_args = array (
'fictioneer_query_name' => 'stories_list',
'post_type' => 'fcn_story',
'post_status' => 'publish',
'order' => $order,
'orderby' => $orderby,
'paged' => $page,
'posts_per_page' => get_option( 'posts_per_page', 8 ),
'update_post_term_cache' => ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' )
);
// Order by words?
if ( $orderby === 'words' ) {
$query_args['orderby'] = 'meta_value_num modified';
$query_args['meta_key'] = 'fictioneer_story_total_word_count';
}
// Order by latest chapter update timestamp?
if ( FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER && $orderby === 'modified' ) {
$query_args['orderby'] = 'meta_value modified';
$query_args['meta_key'] = 'fictioneer_chapters_added';
}
// Append date query (if any)
$query_args = fictioneer_append_date_query( $query_args, $ago, $orderby );
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_stories_query_args', $query_args, $post_id );
// Query stories
$list_of_stories = new WP_Query( $query_args );
// Prime thumbnail cache
if ( function_exists( 'update_post_thumbnail_cache' ) ) {
update_post_thumbnail_cache( $list_of_stories );
}
// Prime author cache
if ( function_exists( 'update_post_author_caches' ) ) {
update_post_author_caches( $list_of_stories->posts );
}
// Header
get_header();
?>
<main id="main" class="main singular stories">
<?php do_action( 'fictioneer_main', 'stories' ); ?>
<div class="main__wrapper">
<?php do_action( 'fictioneer_main_wrapper' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
// Setup
$title = trim( get_the_title() );
$breadcrumb_name = empty( $title ) ? __( 'Stories', 'fictioneer' ) : $title;
$this_breadcrumb = [ $breadcrumb_name, get_the_permalink() ];
// Arguments for hooks and templates/etc.
$hook_args = array(
'current_page' => $page,
'post_id' => $post->ID,
'stories' => $list_of_stories,
'queried_type' => 'fcn_story',
'query_args' => $query_args,
'order' => $order,
'orderby' => $orderby,
'ago' => $ago
);
?>
<article id="singular-<?php echo $post_id; ?>" class="singular__article stories__article">
<?php if ( ! empty( $title ) ) : ?>
<header class="singular__header stories__header">
<h1 class="singular__title stories__title"><?php echo $title; ?></h1>
</header>
<?php endif; ?>
<?php if ( get_the_content() ) : ?>
<section class="singular__content stories__content content-section">
<?php the_content(); ?>
</section>
<?php endif; ?>
<?php
// Renders statistics and list of stories
do_action( 'fictioneer_stories_after_content', $hook_args );
?>
</article>
<?php endwhile; ?>
</div>
<?php do_action( 'fictioneer_main_end', 'stories' ); ?>
</main>
<?php
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => $post_id,
'current_page' => $page,
'stories' => $list_of_stories,
'breadcrumbs' => array(
[fcntr( 'frontpage' ), get_home_url()]
)
);
// Add current breadcrumb
$footer_args['breadcrumbs'][] = $this_breadcrumb;
// Get footer with breadcrumbs
get_footer( null, $footer_args );
?>