PageRenderTime 70ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/twentyfourteen/inc/template-tags.php

https://gitlab.com/math4youbyusgroupillinois/WordPress
PHP | 224 lines | 134 code | 26 blank | 64 comment | 30 complexity | d9728fafce781cdd98dc0ddf225a83c3 MD5 | raw file
  1. <?php
  2. /**
  3. * Custom template tags for Twenty Fourteen
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Fourteen
  7. * @since Twenty Fourteen 1.0
  8. */
  9. if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) :
  10. /**
  11. * Display navigation to next/previous set of posts when applicable.
  12. *
  13. * @since Twenty Fourteen 1.0
  14. *
  15. * @global WP_Query $wp_query WordPress Query object.
  16. * @global WP_Rewrite $wp_rewrite WordPress Rewrite object.
  17. */
  18. function twentyfourteen_paging_nav() {
  19. global $wp_query, $wp_rewrite;
  20. // Don't print empty markup if there's only one page.
  21. if ( $wp_query->max_num_pages < 2 ) {
  22. return;
  23. }
  24. $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  25. $pagenum_link = html_entity_decode( get_pagenum_link() );
  26. $query_args = array();
  27. $url_parts = explode( '?', $pagenum_link );
  28. if ( isset( $url_parts[1] ) ) {
  29. wp_parse_str( $url_parts[1], $query_args );
  30. }
  31. $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  32. $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  33. $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  34. $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
  35. // Set up paginated links.
  36. $links = paginate_links( array(
  37. 'base' => $pagenum_link,
  38. 'format' => $format,
  39. 'total' => $wp_query->max_num_pages,
  40. 'current' => $paged,
  41. 'mid_size' => 1,
  42. 'add_args' => array_map( 'urlencode', $query_args ),
  43. 'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
  44. 'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
  45. ) );
  46. if ( $links ) :
  47. ?>
  48. <nav class="navigation paging-navigation" role="navigation">
  49. <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
  50. <div class="pagination loop-pagination">
  51. <?php echo $links; ?>
  52. </div><!-- .pagination -->
  53. </nav><!-- .navigation -->
  54. <?php
  55. endif;
  56. }
  57. endif;
  58. if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
  59. /**
  60. * Display navigation to next/previous post when applicable.
  61. *
  62. * @since Twenty Fourteen 1.0
  63. */
  64. function twentyfourteen_post_nav() {
  65. // Don't print empty markup if there's nowhere to navigate.
  66. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  67. $next = get_adjacent_post( false, '', false );
  68. if ( ! $next && ! $previous ) {
  69. return;
  70. }
  71. ?>
  72. <nav class="navigation post-navigation" role="navigation">
  73. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
  74. <div class="nav-links">
  75. <?php
  76. if ( is_attachment() ) :
  77. previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
  78. else :
  79. previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
  80. next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
  81. endif;
  82. ?>
  83. </div><!-- .nav-links -->
  84. </nav><!-- .navigation -->
  85. <?php
  86. }
  87. endif;
  88. if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
  89. /**
  90. * Print HTML with meta information for the current post-date/time and author.
  91. *
  92. * @since Twenty Fourteen 1.0
  93. */
  94. function twentyfourteen_posted_on() {
  95. if ( is_sticky() && is_home() && ! is_paged() ) {
  96. echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
  97. }
  98. // Set up and print post meta information.
  99. printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
  100. esc_url( get_permalink() ),
  101. esc_attr( get_the_date( 'c' ) ),
  102. esc_html( get_the_date() ),
  103. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  104. get_the_author()
  105. );
  106. }
  107. endif;
  108. /**
  109. * Find out if blog has more than one category.
  110. *
  111. * @since Twenty Fourteen 1.0
  112. *
  113. * @return boolean true if blog has more than 1 category
  114. */
  115. function twentyfourteen_categorized_blog() {
  116. if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
  117. // Create an array of all the categories that are attached to posts
  118. $all_the_cool_cats = get_categories( array(
  119. 'hide_empty' => 1,
  120. ) );
  121. // Count the number of categories that are attached to the posts
  122. $all_the_cool_cats = count( $all_the_cool_cats );
  123. set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
  124. }
  125. if ( 1 !== (int) $all_the_cool_cats ) {
  126. // This blog has more than 1 category so twentyfourteen_categorized_blog should return true
  127. return true;
  128. } else {
  129. // This blog has only 1 category so twentyfourteen_categorized_blog should return false
  130. return false;
  131. }
  132. }
  133. /**
  134. * Flush out the transients used in twentyfourteen_categorized_blog.
  135. *
  136. * @since Twenty Fourteen 1.0
  137. */
  138. function twentyfourteen_category_transient_flusher() {
  139. // Like, beat it. Dig?
  140. delete_transient( 'twentyfourteen_category_count' );
  141. }
  142. add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
  143. add_action( 'save_post', 'twentyfourteen_category_transient_flusher' );
  144. /**
  145. * Display an optional post thumbnail.
  146. *
  147. * Wraps the post thumbnail in an anchor element on index
  148. * views, or a div element when on single views.
  149. *
  150. * @since Twenty Fourteen 1.0
  151. */
  152. function twentyfourteen_post_thumbnail() {
  153. if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
  154. return;
  155. }
  156. if ( is_singular() ) :
  157. ?>
  158. <div class="post-thumbnail">
  159. <?php
  160. if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
  161. the_post_thumbnail( 'twentyfourteen-full-width' );
  162. } else {
  163. the_post_thumbnail();
  164. }
  165. ?>
  166. </div>
  167. <?php else : ?>
  168. <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
  169. <?php
  170. if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
  171. the_post_thumbnail( 'twentyfourteen-full-width' );
  172. } else {
  173. the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
  174. }
  175. ?>
  176. </a>
  177. <?php endif; // End is_singular()
  178. }
  179. if ( ! function_exists( 'twentyfourteen_excerpt_more' ) && ! is_admin() ) :
  180. /**
  181. * Replaces "[...]" (appended to automatically generated excerpts) with ...
  182. * and a Continue reading link.
  183. *
  184. * @since Twenty Fourteen 1.3
  185. *
  186. * @param string $more Default Read More excerpt link.
  187. * @return string Filtered Read More excerpt link.
  188. */
  189. function twentyfourteen_excerpt_more( $more ) {
  190. $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
  191. esc_url( get_permalink( get_the_ID() ) ),
  192. /* translators: %s: Name of current post */
  193. sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  194. );
  195. return ' &hellip; ' . $link;
  196. }
  197. add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );
  198. endif;