1 | <?php |
||
2 | /** |
||
3 | * Custom template tags for this theme |
||
4 | * |
||
5 | * Eventually, some of the functionality here could be replaced by core features. |
||
6 | * |
||
7 | * @package WordPress |
||
8 | * @subpackage Strip |
||
9 | */ |
||
10 | |||
11 | /** |
||
12 | * Add custom header image to header area |
||
13 | */ |
||
14 | function strip_header_background() { |
||
15 | if ( get_header_image() ) { |
||
16 | $css = '.site-branding { background-image: url(' . esc_url( get_header_image() ) . '); }'; |
||
17 | wp_add_inline_style( 'strip-style', $css ); |
||
18 | } |
||
19 | } |
||
20 | add_action( 'wp_enqueue_scripts', 'strip_header_background', 11 ); |
||
21 | |||
22 | if ( ! function_exists( 'strip_entry_meta' ) ) : |
||
23 | /** |
||
24 | * Prints HTML with meta information for the current post-date/time and author. |
||
25 | */ |
||
26 | function strip_entry_meta() { |
||
27 | if ( is_sticky() && is_home() ) { |
||
28 | printf( |
||
29 | wp_kses( '<span class="featured-post"><a href="%1$s" title="%2$s" rel="bookmark">Sticky</a></span>', 'strip' ), |
||
30 | esc_url( get_permalink() ), |
||
31 | esc_attr( get_the_time() ) |
||
32 | ); |
||
33 | } |
||
34 | |||
35 | if ( 'post' === get_post_type() ) { |
||
36 | printf( |
||
37 | wp_kses_post( '<span class="entry-date"><a href="%1$s" title="%2$s" rel="bookmark"><time datetime="%3$s">%4$s</time></a></span><span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span>', 'strip' ), |
||
38 | esc_url( get_permalink() ), |
||
39 | esc_attr( get_the_time() ), |
||
40 | esc_attr( get_the_date( 'c' ) ), |
||
41 | get_the_date(), |
||
42 | esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
||
43 | esc_attr( sprintf( __( 'View all posts by %s', 'strip' ), get_the_author() ) ), |
||
44 | get_the_author() |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'strip' ) ); |
||
49 | if ( $tags_list ) { |
||
50 | printf( '<span class="tags-links">' . esc_html( '%1$s', 'strip' ) . '</span>', $tags_list ); // WPCS: XSS OK. |
||
51 | } |
||
52 | } |
||
53 | endif; |
||
54 | |||
55 | if ( ! function_exists( 'strip_term_description' ) ) : |
||
56 | /** |
||
57 | * Display optional term description for category, tag and custom taxonomy pages. |
||
58 | * |
||
59 | * @since Strip 1.0 |
||
60 | */ |
||
61 | function strip_term_description() { |
||
62 | // Show an optional term description. |
||
63 | $term_description = term_description(); |
||
64 | |||
65 | if ( is_post_type_archive( 'comic' ) || is_category() || is_tag() || is_tax( 'story' ) && ! empty( $term_description ) ) : |
||
66 | printf( '<div class="taxonomy-description">%s</div>', $term_description, 'strip' ); // WPCS: XSS OK. |
||
67 | endif; |
||
68 | } |
||
69 | endif; // ends check for strip_term_description. |
||
70 | |||
71 | /** |
||
72 | * Returns true if a blog has more than 1 category. |
||
73 | * |
||
74 | * @return bool |
||
75 | */ |
||
76 | function strip_categorized_blog() { |
||
77 | $category_count = get_transient( 'strip_categories' ); |
||
78 | |||
79 | if ( false === $category_count ) { |
||
80 | // Create an array of all the categories that are attached to posts. |
||
81 | $categories = get_categories( array( |
||
82 | 'fields' => 'ids', |
||
83 | 'hide_empty' => 1, |
||
84 | // We only need to know if there is more than one category. |
||
85 | 'number' => 2, |
||
86 | ) ); |
||
87 | |||
88 | // Count the number of categories that are attached to the posts. |
||
89 | $category_count = count( $categories ); |
||
90 | |||
91 | set_transient( 'strip_categories', $category_count ); |
||
92 | } |
||
93 | |||
94 | // Allow viewing case of 0 or 1 categories in post preview. |
||
95 | if ( is_preview() ) { |
||
96 | return true; |
||
97 | } |
||
98 | |||
99 | return $category_count > 1; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Flush out the transients used in strip_categorized_blog. |
||
104 | */ |
||
105 | function strip_category_transient_flusher() { |
||
106 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
||
107 | return; |
||
108 | } |
||
109 | // Like, beat it. Dig? |
||
110 | delete_transient( 'strip_categories' ); |
||
111 | } |
||
112 | add_action( 'edit_category', 'strip_category_transient_flusher' ); |
||
113 | add_action( 'save_post', 'strip_category_transient_flusher' ); |
||
114 | |||
115 | if ( ! function_exists( 'strip_the_custom_logo' ) ) : |
||
116 | /** |
||
117 | * Displays the optional custom logo. |
||
118 | * |
||
119 | * Does nothing if the custom logo is not available. |
||
120 | * |
||
121 | * @since strip 1.0 |
||
122 | */ |
||
123 | function strip_the_custom_logo() { |
||
124 | if ( function_exists( 'the_custom_logo' ) ) { |
||
125 | the_custom_logo(); |
||
126 | } |
||
127 | } |
||
128 | endif; |
||
129 | |||
130 | /** |
||
131 | * Display navigation to next/previous pages when applicable |
||
132 | * TO DO clean up |
||
133 | */ |
||
134 | if ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_post_type_archive( 'comic' ) || is_search() ) ) : // navigation links for home, archive, and search pages |
||
135 | |||
136 | the_posts_pagination( array( |
||
137 | 'prev_text' => _x( '←', 'Previous page link', 'strip' ) . '<span class="screen-reader-text">' . __( 'Previous page', 'strip' ) . '</span>', |
||
138 | 'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'strip' ) . '</span>' . _x( '→', 'Next post link', 'strip' ), |
||
139 | 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'strip' ) . ' </span>', |
||
140 | ) ); |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
141 | endif; |
||
142 | |||
143 | /** |
||
144 | * Get the first and last custom type post using get_boundary_post() |
||
145 | * |
||
146 | * @link https://core.trac.wordpress.org/ticket/27094 |
||
147 | * |
||
148 | * @param bool $in_same_term Optional. Whether returned post should be in a same taxonomy term. |
||
149 | * @param bool $start Optional. Whether to retrieve first or last post. |
||
150 | * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
||
151 | * @return mixed Array containing the boundary post object if successful, null otherwise. |
||
152 | */ |
||
153 | function get_comic_boundary_post( $in_same_term, $start, $taxonomy ) { |
||
154 | global $post; |
||
155 | setup_postdata( $post ); |
||
156 | if ( ! taxonomy_exists( $taxonomy ) ) { |
||
157 | return null; |
||
158 | } |
||
159 | |||
160 | $query_args = array( |
||
161 | 'post_type' => 'comic', |
||
162 | 'posts_per_page' => 1, |
||
163 | 'order' => $start ? 'ASC' : 'DESC', |
||
164 | /*'no_found_rows' => true,*/ |
||
165 | 'update_post_term_cache' => false, |
||
166 | 'update_post_meta_cache' => false, |
||
167 | ); |
||
168 | |||
169 | $term_array = array(); |
||
170 | if ( $in_same_term ) { |
||
171 | if ( $in_same_term ) { |
||
172 | $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); |
||
173 | } |
||
174 | $query_args['tax_query'] = array( array( |
||
175 | 'taxonomy' => $taxonomy, |
||
176 | 'terms' => array_merge( $term_array ), |
||
177 | ), |
||
178 | ); |
||
179 | } |
||
180 | |||
181 | $get_posts = new wp_query; |
||
182 | return $get_posts -> query( $query_args ); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Link to the first comic post in same term |
||
187 | */ |
||
188 | function first_comic_link() { |
||
189 | $first = get_comic_boundary_post( true, true, 'story' ); |
||
190 | apply_filters( 'the_title', $first[0]->post_title ); |
||
191 | |||
192 | echo esc_html( get_permalink( $first[0]->ID ) ); |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * Link to the last comic post in same term |
||
197 | */ |
||
198 | function last_comic_link() { |
||
199 | $last = get_comic_boundary_post( true, false, 'story' ); |
||
200 | apply_filters( 'the_title', $last[0]->post_title ); |
||
201 | |||
202 | echo esc_html( get_permalink( $last[0]->ID ) ); |
||
203 | } |
||
204 |