davvalent commited on 2023-08-01 16:23:42
Showing 2 changed files, with 435 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,434 @@ |
| 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 Rookie |
|
| 8 |
+ */ |
|
| 9 |
+ |
|
| 10 |
+if ( ! function_exists( 'rookie_header_widgets' ) ) : |
|
| 11 |
+/** |
|
| 12 |
+ * Display header widgets section. |
|
| 13 |
+ */ |
|
| 14 |
+function rookie_header_widgets() {
|
|
| 15 |
+ if ( is_active_sidebar( 'header-1' ) ) {
|
|
| 16 |
+ ?> |
|
| 17 |
+ <div id="tertiary" class="site-widgets" role="complementary"> |
|
| 18 |
+ <div class="site-widget-region"> |
|
| 19 |
+ <?php dynamic_sidebar( 'header-1' ); ?> |
|
| 20 |
+ </div> |
|
| 21 |
+ </div><!-- .site-widgets --> |
|
| 22 |
+ <?php |
|
| 23 |
+ } |
|
| 24 |
+} |
|
| 25 |
+endif; |
|
| 26 |
+ |
|
| 27 |
+if ( ! function_exists( 'rookie_header_branding' ) ) : |
|
| 28 |
+/** |
|
| 29 |
+ * Display header branding section. |
|
| 30 |
+ */ |
|
| 31 |
+function rookie_header_branding( $options = array() ) {
|
|
| 32 |
+ ?> |
|
| 33 |
+ <div class="site-branding<?php if ( ! isset( $options['logo_url'] ) && ! $options['display_header_text'] ) { ?> site-branding-empty<?php } ?>">
|
|
| 34 |
+ <div class="site-identity"> |
|
| 35 |
+ <?php if ( isset( $options['logo_url'] ) ) { ?>
|
|
| 36 |
+ <a class="site-logo" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><img src="<?php echo $options['logo_url']; ?>" alt="<?php bloginfo( 'name' ); ?>"></a> |
|
| 37 |
+ <?php } ?> |
|
| 38 |
+ <?php if ( $options['display_header_text'] ) { ?>
|
|
| 39 |
+ <hgroup class="site-hgroup" style="color: #<?php echo $options['header_textcolor']; ?>"> |
|
| 40 |
+ <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> |
|
| 41 |
+ <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2> |
|
| 42 |
+ </hgroup> |
|
| 43 |
+ <?php } ?> |
|
| 44 |
+ </div> |
|
| 45 |
+ </div><!-- .site-branding --> |
|
| 46 |
+ <?php |
|
| 47 |
+} |
|
| 48 |
+endif; |
|
| 49 |
+ |
|
| 50 |
+if ( ! function_exists( 'rookie_header_banner' ) ) : |
|
| 51 |
+/** |
|
| 52 |
+ * Display header banner section. |
|
| 53 |
+ */ |
|
| 54 |
+function rookie_header_banner() {
|
|
| 55 |
+ ?> |
|
| 56 |
+ <div class="site-banner"> |
|
| 57 |
+ <img class="site-banner-image" src="<?php header_image(); ?>" alt="<?php bloginfo( 'description' ); ?>"> |
|
| 58 |
+ </div><!-- .site-banner --> |
|
| 59 |
+ <?php |
|
| 60 |
+} |
|
| 61 |
+endif; |
|
| 62 |
+ |
|
| 63 |
+if ( ! function_exists( 'rookie_header_menu' ) ) : |
|
| 64 |
+/** |
|
| 65 |
+ * Display header menu section. |
|
| 66 |
+ */ |
|
| 67 |
+function rookie_header_menu( $options = array() ) {
|
|
| 68 |
+ ?> |
|
| 69 |
+ <div class="site-menu"> |
|
| 70 |
+ <nav id="site-navigation" class="main-navigation" role="navigation"> |
|
| 71 |
+ <button class="menu-toggle" aria-controls="menu" aria-expanded="false"><span class="dashicons dashicons-menu"></span></button> |
|
| 72 |
+ <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?> |
|
| 73 |
+ <?php if ( $options['has_search'] ) get_search_form(); ?> |
|
| 74 |
+ </nav><!-- #site-navigation --> |
|
| 75 |
+ </div><!-- .site-menu --> |
|
| 76 |
+ <?php |
|
| 77 |
+} |
|
| 78 |
+endif; |
|
| 79 |
+ |
|
| 80 |
+if ( ! function_exists( 'rookie_header_area' ) ) : |
|
| 81 |
+/** |
|
| 82 |
+ * Display header area sections. |
|
| 83 |
+ */ |
|
| 84 |
+function rookie_header_area() {
|
|
| 85 |
+ $options = get_option( 'themeboy', array() ); |
|
| 86 |
+ if ( array_key_exists( 'logo_url', $options ) && ! empty( $options['logo_url'] ) ) {
|
|
| 87 |
+ $options['logo_url'] = esc_url( set_url_scheme( $options['logo_url'] ) ); |
|
| 88 |
+ } |
|
| 89 |
+ |
|
| 90 |
+ if ( ! array_key_exists( 'nav_menu_search', $options ) || $options['nav_menu_search'] ) {
|
|
| 91 |
+ $options['has_search'] = true; |
|
| 92 |
+ } else {
|
|
| 93 |
+ $options['has_search'] = false; |
|
| 94 |
+ } |
|
| 95 |
+ |
|
| 96 |
+ $options['display_header_text'] = display_header_text(); |
|
| 97 |
+ |
|
| 98 |
+ $style_options = apply_filters( 'rookie_header_image_style_options', array( |
|
| 99 |
+ 'background' => __( 'Background', 'rookie' ), |
|
| 100 |
+ 'image' => __( 'Image', 'rookie' ), |
|
| 101 |
+ ) ); |
|
| 102 |
+ |
|
| 103 |
+ reset( $style_options ); |
|
| 104 |
+ $options['style'] = key( $style_options ); |
|
| 105 |
+ |
|
| 106 |
+ if ( array_key_exists( 'header_image_style', $options ) && array_key_exists( $options['header_image_style'], $style_options ) ) {
|
|
| 107 |
+ $options['style'] = $options['header_image_style']; |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ $options['header'] = get_header_image(); |
|
| 111 |
+ |
|
| 112 |
+ $options['header_textcolor'] = get_header_textcolor(); |
|
| 113 |
+ $options['header_textcolor'] = str_replace( '#', '', $options['header_textcolor'] ); |
|
| 114 |
+ |
|
| 115 |
+ $sections = apply_filters( 'rookie_header_area_sections', array( |
|
| 116 |
+ 'widgets', |
|
| 117 |
+ 'branding', |
|
| 118 |
+ 'banner', |
|
| 119 |
+ 'menu', |
|
| 120 |
+ ) ); |
|
| 121 |
+ ?> |
|
| 122 |
+ <?php if ( $options['header'] && 'background' == $options['style'] ) { ?>
|
|
| 123 |
+ <div class="header-area header-area-custom<?php if ( isset( $options['logo_url'] ) ) { ?> header-area-has-logo<?php } ?><?php if ( $options['has_search'] ) { ?> header-area-has-search<?php } ?><?php if ( $options['display_header_text'] ) { ?> header-area-has-text<?php } ?>" style="background-image: url(<?php header_image(); ?>);">
|
|
| 124 |
+ <?php } else { ?>
|
|
| 125 |
+ <div class="header-area<?php if ( isset( $options['logo_url'] ) ) { ?> header-area-has-logo<?php } ?><?php if ( $options['has_search'] ) { ?> header-area-has-search<?php } ?>">
|
|
| 126 |
+ <?php } ?> |
|
| 127 |
+ <?php do_action( 'rookie_before_header_area', $options, $sections ); ?> |
|
| 128 |
+ <div class="header-inner"> |
|
| 129 |
+ <?php |
|
| 130 |
+ foreach ( $sections as $section ) {
|
|
| 131 |
+ if ( 'widgets' == $section ) {
|
|
| 132 |
+ rookie_header_widgets(); |
|
| 133 |
+ } elseif ( 'banner' == $section && $options['header'] && 'image' == $options['style'] ) {
|
|
| 134 |
+ rookie_header_banner(); |
|
| 135 |
+ } elseif ( 'branding' == $section ) {
|
|
| 136 |
+ rookie_header_branding( $options ); |
|
| 137 |
+ } elseif ( 'menu' == $section ) {
|
|
| 138 |
+ rookie_header_menu( $options ); |
|
| 139 |
+ } else {
|
|
| 140 |
+ do_action( 'rookie_header_area_section_' . $section, $options ); |
|
| 141 |
+ } |
|
| 142 |
+ } |
|
| 143 |
+ ?> |
|
| 144 |
+ </div><!-- .header-inner --> |
|
| 145 |
+ <?php do_action( 'rookie_after_header_area', $options, $sections ); ?> |
|
| 146 |
+ </div><!-- .header-area --> |
|
| 147 |
+ <?php |
|
| 148 |
+} |
|
| 149 |
+endif; |
|
| 150 |
+ |
|
| 151 |
+if ( ! function_exists( 'rookie_paging_nav' ) ) : |
|
| 152 |
+/** |
|
| 153 |
+ * Display navigation to next/previous set of posts when applicable. |
|
| 154 |
+ */ |
|
| 155 |
+function rookie_paging_nav() {
|
|
| 156 |
+ // Don't print empty markup if there's only one page. |
|
| 157 |
+ if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
|
|
| 158 |
+ return; |
|
| 159 |
+ } |
|
| 160 |
+ ?> |
|
| 161 |
+ <nav class="navigation paging-navigation" role="navigation"> |
|
| 162 |
+ <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'rookie' ); ?></h1> |
|
| 163 |
+ <div class="nav-links"> |
|
| 164 |
+ |
|
| 165 |
+ <?php if ( get_next_posts_link() ) : ?> |
|
| 166 |
+ <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'rookie' ) ); ?></div> |
|
| 167 |
+ <?php endif; ?> |
|
| 168 |
+ |
|
| 169 |
+ <?php if ( get_previous_posts_link() ) : ?> |
|
| 170 |
+ <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'rookie' ) ); ?></div> |
|
| 171 |
+ <?php endif; ?> |
|
| 172 |
+ |
|
| 173 |
+ </div><!-- .nav-links --> |
|
| 174 |
+ </nav><!-- .navigation --> |
|
| 175 |
+ <?php |
|
| 176 |
+} |
|
| 177 |
+endif; |
|
| 178 |
+ |
|
| 179 |
+if ( ! function_exists( 'rookie_post_nav' ) ) : |
|
| 180 |
+/** |
|
| 181 |
+ * Display navigation to next/previous post when applicable. |
|
| 182 |
+ */ |
|
| 183 |
+function rookie_post_nav() {
|
|
| 184 |
+ // Don't print empty markup if there's nowhere to navigate. |
|
| 185 |
+ $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); |
|
| 186 |
+ $next = get_adjacent_post( false, '', false ); |
|
| 187 |
+ |
|
| 188 |
+ if ( ! $next && ! $previous ) {
|
|
| 189 |
+ return; |
|
| 190 |
+ } |
|
| 191 |
+ ?> |
|
| 192 |
+ <nav class="navigation post-navigation" role="navigation"> |
|
| 193 |
+ <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'rookie' ); ?></h1> |
|
| 194 |
+ <div class="nav-links"> |
|
| 195 |
+ <?php |
|
| 196 |
+ previous_post_link( '<div class="nav-previous">%link</div>', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'rookie' ) ); |
|
| 197 |
+ next_post_link( '<div class="nav-next">%link</div>', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'rookie' ) ); |
|
| 198 |
+ ?> |
|
| 199 |
+ </div><!-- .nav-links --> |
|
| 200 |
+ </nav><!-- .navigation --> |
|
| 201 |
+ <?php |
|
| 202 |
+} |
|
| 203 |
+endif; |
|
| 204 |
+ |
|
| 205 |
+if ( ! function_exists( 'rookie_entry_title' ) ) : |
|
| 206 |
+/** |
|
| 207 |
+ * Prints HTML with title and author. |
|
| 208 |
+ */ |
|
| 209 |
+function rookie_entry_title() {
|
|
| 210 |
+ the_title( '<h1 class="entry-title single-entry-title">', '</h1>' ); |
|
| 211 |
+} |
|
| 212 |
+endif; |
|
| 213 |
+ |
|
| 214 |
+if ( ! function_exists( 'rookie_entry_date' ) ) : |
|
| 215 |
+/** |
|
| 216 |
+ * Prints HTML with meta information for the current post-date/time. |
|
| 217 |
+ */ |
|
| 218 |
+function rookie_entry_date() {
|
|
| 219 |
+ $options = get_option( 'themeboy', array() ); |
|
| 220 |
+ |
|
| 221 |
+ $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; |
|
| 222 |
+ if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
|
| 223 |
+ $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; |
|
| 224 |
+ } |
|
| 225 |
+ |
|
| 226 |
+ $time_string = sprintf( $time_string, |
|
| 227 |
+ esc_attr( get_the_date( 'c' ) ), |
|
| 228 |
+ esc_html( get_the_date() ), |
|
| 229 |
+ esc_attr( get_the_modified_date( 'c' ) ), |
|
| 230 |
+ esc_html( get_the_modified_date() ) |
|
| 231 |
+ ); |
|
| 232 |
+ |
|
| 233 |
+ $posted_on = ''; |
|
| 234 |
+ |
|
| 235 |
+ if ( ! array_key_exists( 'show_post_date', $options ) || $options['show_post_date'] ) {
|
|
| 236 |
+ $posted_on .= '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'; |
|
| 237 |
+ } |
|
| 238 |
+ |
|
| 239 |
+ if ( array_key_exists( 'show_post_author', $options ) && $options['show_post_author'] ) {
|
|
| 240 |
+ $byline = sprintf( |
|
| 241 |
+ _x( 'by %s', 'post author', 'rookie' ), |
|
| 242 |
+ '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>' |
|
| 243 |
+ ); |
|
| 244 |
+ $posted_on .= ' <span class="byline">' . $byline . '</span>'; |
|
| 245 |
+ } |
|
| 246 |
+ |
|
| 247 |
+ if ( '' !== $posted_on ) {
|
|
| 248 |
+ echo '<span class="posted-on">' . $posted_on . '</span>'; |
|
| 249 |
+ } |
|
| 250 |
+} |
|
| 251 |
+endif; |
|
| 252 |
+ |
|
| 253 |
+if ( ! function_exists( 'rookie_entry_meta' ) ) : |
|
| 254 |
+/** |
|
| 255 |
+ * Prints HTML with meta information for the categories and comments. |
|
| 256 |
+ */ |
|
| 257 |
+function rookie_entry_meta() {
|
|
| 258 |
+ // Hide category and tag text for pages. |
|
| 259 |
+ if ( 'post' == get_post_type() && rookie_categorized_blog() ) {
|
|
| 260 |
+ $categories_list = get_the_category_list( ' ' ); |
|
| 261 |
+ if ( $categories_list ) {
|
|
| 262 |
+ ?> |
|
| 263 |
+ <div class="entry-meta"> |
|
| 264 |
+ <div class="entry-category-links"> |
|
| 265 |
+ <?php echo $categories_list; ?> |
|
| 266 |
+ </div><!-- .entry-category-links --> |
|
| 267 |
+ </div><!-- .entry-meta --> |
|
| 268 |
+ <?php |
|
| 269 |
+ } |
|
| 270 |
+ } |
|
| 271 |
+} |
|
| 272 |
+endif; |
|
| 273 |
+ |
|
| 274 |
+if ( ! function_exists( 'rookie_entry_footer' ) ) : |
|
| 275 |
+/** |
|
| 276 |
+ * Prints HTML with meta information for the tags. |
|
| 277 |
+ */ |
|
| 278 |
+function rookie_entry_footer() {
|
|
| 279 |
+ // Hide category and tag text for pages. |
|
| 280 |
+ if ( 'post' == get_post_type() ) {
|
|
| 281 |
+ $tags_list = get_the_tag_list( '', ' ' ); |
|
| 282 |
+ |
|
| 283 |
+ if ( $tags_list ) {
|
|
| 284 |
+ ?> |
|
| 285 |
+ <footer class="entry-footer"> |
|
| 286 |
+ <div class="entry-tag-links"> |
|
| 287 |
+ <?php echo $tags_list; ?> |
|
| 288 |
+ </div><!-- .entry-tag-links --> |
|
| 289 |
+ </footer><!-- .entry-footer --> |
|
| 290 |
+ <?php |
|
| 291 |
+ } |
|
| 292 |
+ } |
|
| 293 |
+} |
|
| 294 |
+endif; |
|
| 295 |
+ |
|
| 296 |
+if ( ! function_exists( 'the_archive_title' ) ) : |
|
| 297 |
+/** |
|
| 298 |
+ * Shim for `the_archive_title()`. |
|
| 299 |
+ * |
|
| 300 |
+ * Display the archive title based on the queried object. |
|
| 301 |
+ * |
|
| 302 |
+ * @todo Remove this function when WordPress 4.3 is released. |
|
| 303 |
+ * |
|
| 304 |
+ * @param string $before Optional. Content to prepend to the title. Default empty. |
|
| 305 |
+ * @param string $after Optional. Content to append to the title. Default empty. |
|
| 306 |
+ */ |
|
| 307 |
+function the_archive_title( $before = '', $after = '' ) {
|
|
| 308 |
+ if ( is_category() ) {
|
|
| 309 |
+ $title = sprintf( __( 'Category: %s', 'rookie' ), single_cat_title( '', false ) ); |
|
| 310 |
+ } elseif ( is_tag() ) {
|
|
| 311 |
+ $title = sprintf( __( 'Tag: %s', 'rookie' ), single_tag_title( '', false ) ); |
|
| 312 |
+ } elseif ( is_author() ) {
|
|
| 313 |
+ $title = sprintf( __( 'Author: %s', 'rookie' ), '<span class="vcard">' . get_the_author() . '</span>' ); |
|
| 314 |
+ } elseif ( is_year() ) {
|
|
| 315 |
+ $title = sprintf( __( 'Year: %s', 'rookie' ), get_the_date( _x( 'Y', 'yearly archives date format', 'rookie' ) ) ); |
|
| 316 |
+ } elseif ( is_month() ) {
|
|
| 317 |
+ $title = sprintf( __( 'Month: %s', 'rookie' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'rookie' ) ) ); |
|
| 318 |
+ } elseif ( is_day() ) {
|
|
| 319 |
+ $title = sprintf( __( 'Day: %s', 'rookie' ), get_the_date( _x( 'F j, Y', 'daily archives date format', 'rookie' ) ) ); |
|
| 320 |
+ } elseif ( is_tax( 'post_format', 'post-format-aside' ) ) {
|
|
| 321 |
+ $title = _x( 'Asides', 'post format archive title', 'rookie' ); |
|
| 322 |
+ } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
|
|
| 323 |
+ $title = _x( 'Galleries', 'post format archive title', 'rookie' ); |
|
| 324 |
+ } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
|
|
| 325 |
+ $title = _x( 'Images', 'post format archive title', 'rookie' ); |
|
| 326 |
+ } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
|
|
| 327 |
+ $title = _x( 'Videos', 'post format archive title', 'rookie' ); |
|
| 328 |
+ } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
|
|
| 329 |
+ $title = _x( 'Quotes', 'post format archive title', 'rookie' ); |
|
| 330 |
+ } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
|
|
| 331 |
+ $title = _x( 'Links', 'post format archive title', 'rookie' ); |
|
| 332 |
+ } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
|
|
| 333 |
+ $title = _x( 'Statuses', 'post format archive title', 'rookie' ); |
|
| 334 |
+ } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
|
|
| 335 |
+ $title = _x( 'Audio', 'post format archive title', 'rookie' ); |
|
| 336 |
+ } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
|
|
| 337 |
+ $title = _x( 'Chats', 'post format archive title', 'rookie' ); |
|
| 338 |
+ } elseif ( is_post_type_archive() ) {
|
|
| 339 |
+ $title = sprintf( __( 'Archives: %s', 'rookie' ), post_type_archive_title( '', false ) ); |
|
| 340 |
+ } elseif ( is_tax() ) {
|
|
| 341 |
+ $tax = get_taxonomy( get_queried_object()->taxonomy ); |
|
| 342 |
+ /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */ |
|
| 343 |
+ $title = sprintf( __( '%1$s: %2$s', 'rookie' ), $tax->labels->singular_name, single_term_title( '', false ) ); |
|
| 344 |
+ } else {
|
|
| 345 |
+ $title = __( 'Archives', 'rookie' ); |
|
| 346 |
+ } |
|
| 347 |
+ |
|
| 348 |
+ /** |
|
| 349 |
+ * Filter the archive title. |
|
| 350 |
+ * |
|
| 351 |
+ * @param string $title Archive title to be displayed. |
|
| 352 |
+ */ |
|
| 353 |
+ $title = apply_filters( 'get_the_archive_title', $title ); |
|
| 354 |
+ |
|
| 355 |
+ if ( ! empty( $title ) ) {
|
|
| 356 |
+ echo $before . $title . $after; |
|
| 357 |
+ } |
|
| 358 |
+} |
|
| 359 |
+endif; |
|
| 360 |
+ |
|
| 361 |
+if ( ! function_exists( 'the_archive_description' ) ) : |
|
| 362 |
+/** |
|
| 363 |
+ * Shim for `the_archive_description()`. |
|
| 364 |
+ * |
|
| 365 |
+ * Display category, tag, or term description. |
|
| 366 |
+ * |
|
| 367 |
+ * @todo Remove this function when WordPress 4.3 is released. |
|
| 368 |
+ * |
|
| 369 |
+ * @param string $before Optional. Content to prepend to the description. Default empty. |
|
| 370 |
+ * @param string $after Optional. Content to append to the description. Default empty. |
|
| 371 |
+ */ |
|
| 372 |
+function the_archive_description( $before = '', $after = '' ) {
|
|
| 373 |
+ $description = apply_filters( 'get_the_archive_description', term_description() ); |
|
| 374 |
+ |
|
| 375 |
+ if ( ! empty( $description ) ) {
|
|
| 376 |
+ /** |
|
| 377 |
+ * Filter the archive description. |
|
| 378 |
+ * |
|
| 379 |
+ * @see term_description() |
|
| 380 |
+ * |
|
| 381 |
+ * @param string $description Archive description to be displayed. |
|
| 382 |
+ */ |
|
| 383 |
+ echo $before . $description . $after; |
|
| 384 |
+ } |
|
| 385 |
+} |
|
| 386 |
+endif; |
|
| 387 |
+ |
|
| 388 |
+if ( ! function_exists( 'rookie_categorized_blog' ) ) : |
|
| 389 |
+/** |
|
| 390 |
+ * Returns true if a blog has more than 1 category. |
|
| 391 |
+ * |
|
| 392 |
+ * @return bool |
|
| 393 |
+ */ |
|
| 394 |
+function rookie_categorized_blog() {
|
|
| 395 |
+ if ( false === ( $all_the_cool_cats = get_transient( 'rookie_categories' ) ) ) {
|
|
| 396 |
+ // Create an array of all the categories that are attached to posts. |
|
| 397 |
+ $all_the_cool_cats = get_categories( array( |
|
| 398 |
+ 'fields' => 'ids', |
|
| 399 |
+ 'hide_empty' => 1, |
|
| 400 |
+ |
|
| 401 |
+ // We only need to know if there is more than one category. |
|
| 402 |
+ 'number' => 2, |
|
| 403 |
+ ) ); |
|
| 404 |
+ |
|
| 405 |
+ // Count the number of categories that are attached to the posts. |
|
| 406 |
+ $all_the_cool_cats = count( $all_the_cool_cats ); |
|
| 407 |
+ |
|
| 408 |
+ set_transient( 'rookie_categories', $all_the_cool_cats ); |
|
| 409 |
+ } |
|
| 410 |
+ |
|
| 411 |
+ if ( $all_the_cool_cats > 1 ) {
|
|
| 412 |
+ // This blog has more than 1 category so rookie_categorized_blog should return true. |
|
| 413 |
+ return true; |
|
| 414 |
+ } else {
|
|
| 415 |
+ // This blog has only 1 category so rookie_categorized_blog should return false. |
|
| 416 |
+ return false; |
|
| 417 |
+ } |
|
| 418 |
+} |
|
| 419 |
+endif; |
|
| 420 |
+ |
|
| 421 |
+if ( ! function_exists( 'rookie_category_transient_flusher' ) ) : |
|
| 422 |
+/** |
|
| 423 |
+ * Flush out the transients used in rookie_categorized_blog. |
|
| 424 |
+ */ |
|
| 425 |
+function rookie_category_transient_flusher() {
|
|
| 426 |
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
|
| 427 |
+ return; |
|
| 428 |
+ } |
|
| 429 |
+ // Like, beat it. Dig? |
|
| 430 |
+ delete_transient( 'rookie_categories' ); |
|
| 431 |
+} |
|
| 432 |
+add_action( 'edit_category', 'rookie_category_transient_flusher' ); |
|
| 433 |
+add_action( 'save_post', 'rookie_category_transient_flusher' ); |
|
| 434 |
+endif; |
|
| 0 | 435 |