/blog/wp-content/themes/sociallyviral/inc/template-tags.php

https://gitlab.com/relacilia/cakra · PHP · 168 lines · 89 code · 14 blank · 65 comment · 16 complexity · 454864c4ff6e4506e793cea5cedfd7a9 MD5 · raw file

  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 SociallyViral
  8. */
  9. if ( ! function_exists( 'sociallyviral_post_navigation' ) ) :
  10. /**
  11. * Display navigation to next/previous post when applicable.
  12. *
  13. * @todo Remove this function when WordPress 4.3 is released.
  14. */
  15. function sociallyviral_post_navigation() {
  16. // Don't print empty markup if there's nowhere to navigate.
  17. // $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  18. // $next = get_adjacent_post( false, '', false );
  19. // if ( ! $next && ! $previous ) {
  20. // return;
  21. // }
  22. ?>
  23. <nav class="navigation posts-navigation" role="navigation">
  24. <!--Start Pagination-->
  25. <?php $sociallyviral_nav_type = get_theme_mod('sociallyviral_pagination_position');
  26. if (!empty($sociallyviral_nav_type)) {
  27. $sociallyviral_pagination = get_the_posts_pagination( array(
  28. 'mid_size' => 2,
  29. 'prev_text' => __( 'Newer', 'sociallyviral' ),
  30. 'next_text' => __( 'Older', 'sociallyviral' ),
  31. ) );
  32. echo $sociallyviral_pagination;
  33. } else { ?>
  34. <h2 class="screen-reader-text"><?php _e( 'Posts navigation', 'sociallyviral' ); ?></h2>
  35. <div class="pagination nav-links">
  36. <?php if ( get_next_posts_link() ) : ?>
  37. <div class="nav-previous"><?php next_posts_link( __( '<i class="demo-icon icon-angle-double-left"></i> Previous', 'sociallyviral' ) ); ?></div>
  38. <?php endif; ?>
  39. <?php if ( get_previous_posts_link() ) : ?>
  40. <div class="nav-next"><?php previous_posts_link( __( 'Next <i class="demo-icon icon-angle-double-right"></i>', 'sociallyviral' ) ); ?></div>
  41. <?php endif; ?>
  42. </div>
  43. <?php } ?>
  44. </nav><!--End Pagination-->
  45. <?php
  46. }
  47. endif;
  48. if ( ! function_exists( 'sociallyviral_archive_title' ) ) :
  49. /**
  50. * Shim for `sociallyviral_archive_title()`.
  51. *
  52. * Display the archive title based on the queried object.
  53. *
  54. * @todo Remove this function when WordPress 4.3 is released.
  55. *
  56. * @param string $before Optional. Content to prepend to the title. Default empty.
  57. * @param string $after Optional. Content to append to the title. Default empty.
  58. */
  59. function sociallyviral_archive_title( $before = '', $after = '' ) {
  60. if ( is_category() ) {
  61. $title = sprintf( __( 'Category: %s', 'sociallyviral' ), single_cat_title( '', false ) );
  62. } elseif ( is_tag() ) {
  63. $title = sprintf( __( 'Tag: %s', 'sociallyviral' ), single_tag_title( '', false ) );
  64. } elseif ( is_author() ) {
  65. $title = sprintf( __( 'Author: %s', 'sociallyviral' ), '<span class="vcard">' . get_the_author() . '</span>' );
  66. } elseif ( is_year() ) {
  67. $title = sprintf( __( 'Year: %s', 'sociallyviral' ), get_the_date( _x( 'Y', 'yearly archives date format', 'sociallyviral' ) ) );
  68. } elseif ( is_month() ) {
  69. $title = sprintf( __( 'Month: %s', 'sociallyviral' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'sociallyviral' ) ) );
  70. } elseif ( is_day() ) {
  71. $title = sprintf( __( 'Day: %s', 'sociallyviral' ), get_the_date( _x( 'F j, Y', 'daily archives date format', 'sociallyviral' ) ) );
  72. } elseif ( is_post_type_archive() ) {
  73. $title = sprintf( __( 'Archives: %s', 'sociallyviral' ), post_type_archive_title( '', false ) );
  74. } elseif ( is_tax() ) {
  75. $tax = get_taxonomy( get_queried_object()->taxonomy );
  76. /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
  77. $title = sprintf( __( '%1$s: %2$s', 'sociallyviral' ), $tax->labels->singular_name, single_term_title( '', false ) );
  78. } else {
  79. $title = __( 'Archives', 'sociallyviral' );
  80. }
  81. /**
  82. * Filter the archive title.
  83. *
  84. * @param string $title Archive title to be displayed.
  85. */
  86. $title = apply_filters( 'get_the_archive_title', $title );
  87. if ( ! empty( $title ) ) {
  88. echo $before . $title . $after;
  89. }
  90. }
  91. endif;
  92. if ( ! function_exists( 'sociallyviral_archive_description' ) ) :
  93. /**
  94. * Shim for `the_archive_description()`.
  95. *
  96. * Display category, tag, or term description.
  97. *
  98. * @todo Remove this function when WordPress 4.3 is released.
  99. *
  100. * @param string $before Optional. Content to prepend to the description. Default empty.
  101. * @param string $after Optional. Content to append to the description. Default empty.
  102. */
  103. function sociallyviral_archive_description( $before = '', $after = '' ) {
  104. $description = apply_filters( 'get_the_archive_description', term_description() );
  105. if ( ! empty( $description ) ) {
  106. /**
  107. * Filter the archive description.
  108. *
  109. * @see term_description()
  110. *
  111. * @param string $description Archive description to be displayed.
  112. */
  113. echo $before . $description . $after;
  114. }
  115. }
  116. endif;
  117. /**
  118. * Returns true if a blog has more than 1 category.
  119. *
  120. * @return bool
  121. */
  122. function sociallyviral_categorized_blog() {
  123. if ( false === ( $all_the_cool_cats = get_transient( 'sociallyviral_categories' ) ) ) {
  124. // Create an array of all the categories that are attached to posts.
  125. $all_the_cool_cats = get_categories( array(
  126. 'fields' => 'ids',
  127. 'hide_empty' => 1,
  128. // We only need to know if there is more than one category.
  129. 'number' => 2,
  130. ) );
  131. // Count the number of categories that are attached to the posts.
  132. $all_the_cool_cats = count( $all_the_cool_cats );
  133. set_transient( 'sociallyviral_categories', $all_the_cool_cats );
  134. }
  135. if ( $all_the_cool_cats > 1 ) {
  136. // This blog has more than 1 category so sociallyviral_categorized_blog should return true.
  137. return true;
  138. } else {
  139. // This blog has only 1 category so sociallyviral_categorized_blog should return false.
  140. return false;
  141. }
  142. }
  143. /**
  144. * Flush out the transients used in sociallyviral_categorized_blog.
  145. */
  146. function sociallyviral_category_transient_flusher() {
  147. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  148. return;
  149. }
  150. // Like, beat it. Dig?
  151. delete_transient( 'sociallyviral_categories' );
  152. }
  153. add_action( 'edit_category', 'sociallyviral_category_transient_flusher' );
  154. add_action( 'save_post', 'sociallyviral_category_transient_flusher' );