BayuAngora

template-tags

Jul 24th, 2019
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  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 annina
  8. */
  9.  
  10. if ( ! function_exists( 'annina_post_nav' ) ) :
  11. /**
  12. * Display navigation to next/previous post when applicable.
  13. */
  14. function annina_post_nav() {
  15. // Don't print empty markup if there's nowhere to navigate.
  16. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  17. $next = get_adjacent_post( false, '', false );
  18.  
  19. if ( ! $next && ! $previous ) {
  20. return;
  21. }
  22. ?>
  23. <nav class="navigation post-navigation" role="navigation">
  24. <h1 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'annina' ); ?></h1>
  25.  
  26. <div class="nav-links">
  27.  
  28. <?php
  29. next_post_link( '<div class="nav-previous">%link</div>', '<div class="meta-nav" title="%title" aria-hidden="true"><i class="fa fa-angle-left spaceRight"></i><span>' . esc_html__( 'Prev', 'annina' ) . '</span></div> ' . '<span class="screen-reader-text">' . esc_html__( 'Prev', 'annina' ) . '</span> ' );
  30. previous_post_link( '<div class="nav-next">%link</div>', '<div class="meta-nav" title="%title" aria-hidden="true"><span>' . esc_html__( 'Next', 'annina' ) . '</span><i class="fa fa-angle-right spaceLeft"></i></div> ' . '<span class="screen-reader-text">' . esc_html__( 'Next', 'annina' ) . '</span> ' );
  31. ?>
  32.  
  33. </div><!-- .nav-links -->
  34.  
  35. </nav><!-- .navigation -->
  36. <?php
  37. }
  38. endif;
  39.  
  40. if ( ! function_exists( 'annina_posted_on' ) ) :
  41. /**
  42. * Prints HTML with meta information for the current post-date/time and author.
  43. */
  44.  
  45. $posted_on = '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark"></a>';
  46.  
  47. echo '<span class="posted-on"></span>'; // WPCS: XSS OK.
  48.  
  49. if ( 'post' == get_post_type() && is_single() ) {
  50. /* translators: used between list items, there is a space after the comma */
  51. $categories_list = get_the_category_list( esc_html__( ' / ', 'annina' ) );
  52. if ( $categories_list && annina_categorized_blog() ) {
  53. echo '<span class="cat-links"><i class="fa fa-folder-open-o spaceLeftRight" aria-hidden="true"></i>' . $categories_list . '</span>';
  54. }
  55. }
  56.  
  57. if ( ! function_exists( 'annina_entry_footer' ) ) :
  58. /**
  59. * Prints HTML with meta information for the categories, tags and comments.
  60. */
  61. function annina_entry_footer() {
  62. // Hide category and tag text for pages.
  63. if ( 'post' == get_post_type() ) {
  64. /* translators: used between list items, there is a space after the comma */
  65. $tags_list = get_the_tag_list( '', esc_html__( ' / ', 'annina' ) );
  66. if ( $tags_list ) {
  67. echo '<span class="tags-links"><i class="fa fa-tags spaceRight" aria-hidden="true"></i>' . $tags_list . '</span>';
  68. }
  69. }
  70. edit_post_link( esc_html__( 'Edit', 'annina' ), '<span class="edit-link"><i class="fa fa-wrench spaceRight" aria-hidden="true"></i>', '</span>' );
  71. }
  72. endif;
  73.  
  74. /**
  75. * Returns true if a blog has more than 1 category.
  76. *
  77. * @return bool
  78. */
  79. function annina_categorized_blog() {
  80. $all_the_cool_cats = get_transient( 'annina_categories' );
  81.  
  82. if ( false === $all_the_cool_cats ) {
  83. // Create an array of all the categories that are attached to posts.
  84. $categories = get_categories( array(
  85. 'fields' => 'ids',
  86. 'hide_empty' => 1,
  87. // We only need to know if there is more than one category.
  88. 'number' => 2,
  89. ) );
  90.  
  91. // Count the number of categories that are attached to the posts.
  92. $all_the_cool_cats = count( $categories );
  93.  
  94. set_transient( 'annina_categories', $all_the_cool_cats );
  95. }
  96.  
  97. return $all_the_cool_cats > 1;
  98. }
  99.  
  100. /**
  101. * Flush out the transients used in annina_categorized_blog.
  102. */
  103. function annina_category_transient_flusher() {
  104. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  105. return;
  106. }
  107. // Like, beat it. Dig?
  108. delete_transient( 'annina_categories' );
  109. }
  110. add_action( 'edit_category', 'annina_category_transient_flusher' );
  111. add_action( 'save_post', 'annina_category_transient_flusher' );
Advertisement
Add Comment
Please, Sign In to add comment