Advertisement
Guest User

Jester -- template-tags.php

a guest
Apr 6th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.26 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 Jester
  8.  */
  9.  
  10. if ( ! function_exists( 'jester_paging_nav' ) ) :
  11. /**
  12.  * Display navigation to next/previous set of posts when applicable.
  13.  *
  14.  * @return void
  15.  */
  16. function jester_paging_nav() {
  17.     // Don't print empty markup if there's only one page.
  18.     if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  19.         return;
  20.     }
  21.     ?>
  22.    
  23.     <hr />
  24.    
  25.     <nav class="navigation paging-navigation" role="navigation">
  26.         <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'jester' ); ?></h1>
  27.         <div class="nav-links">
  28.  
  29.             <?php if ( get_next_posts_link() ) : ?>
  30.             <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'jester' ) ); ?></div>
  31.             <?php endif; ?>
  32.  
  33.             <?php if ( get_previous_posts_link() ) : ?>
  34.             <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'jester' ) ); ?></div>
  35.             <?php endif; ?>
  36.  
  37.         </div><!-- .nav-links -->
  38.     </nav><!-- .navigation -->
  39.     <?php
  40. }
  41. endif;
  42.  
  43. if ( ! function_exists( 'jester_post_nav' ) ) :
  44. /**
  45.  * Display navigation to next/previous post when applicable.
  46.  *
  47.  * @return void
  48.  */
  49. function jester_post_nav() {
  50.     // Don't print empty markup if there's nowhere to navigate.
  51.     $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  52.     $next     = get_adjacent_post( false, '', false );
  53.  
  54.     if ( ! $next && ! $previous ) {
  55.         return;
  56.     }
  57.     ?>
  58.    
  59.     <hr />
  60.    
  61.     <nav class="navigation post-navigation" role="navigation">
  62.         <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'jester' ); ?></h1>
  63.         <div class="nav-links">
  64.             <?php
  65.                 previous_post_link( '<div class="nav-previous">%link</div>', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'jester' ) );
  66.                 next_post_link(     '<div class="nav-next">%link</div>',     _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link',     'jester' ) );
  67.             ?>
  68.         </div><!-- .nav-links -->
  69.     </nav><!-- .navigation -->
  70.     <?php
  71. }
  72. endif;
  73.  
  74. if ( ! function_exists( 'jester_entry_meta' ) ) :
  75. /**
  76.  * Prints HTML with all meta information: post date, author, tags, etc.
  77.  */
  78. function jester_entry_meta() {
  79.   global $post;
  80.    
  81.   if ( wp_attachment_is_image() && 'attachment' == $post->post_type ) :
  82.     $attachment_metadata = wp_get_attachment_metadata( $post->ID );
  83.     printf( __( '<li class="zoom meta-text"><a href="%1$s">See full-size image: (%2$s x %3$s)</span></li>', 'jester' ),
  84.       esc_html( wp_get_attachment_url( $post->ID ) ),
  85.       $attachment_metadata[ 'height' ],
  86.       $attachment_metadata[ 'width' ]
  87.     );
  88.   endif;
  89.    
  90.   $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
  91.    
  92.     if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  93.         $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
  94.     }
  95.  
  96.     $time_string = sprintf( $time_string,
  97.         esc_attr( get_the_date( 'c' ) ),
  98.         esc_html( get_the_date() ),
  99.         esc_attr( get_the_modified_date( 'c' ) ),
  100.         esc_html( get_the_modified_date() )
  101.     );
  102.  
  103.   printf( __( '<li class="posted-on meta-text">Date: %s</li>', 'jester' ),
  104.     sprintf( '<a href="%1$s" rel="bookmark">%2$s</a>',
  105.       esc_url( get_permalink() ),
  106.       $time_string
  107.     )
  108.   );
  109.    
  110.   printf( __( '<li class="author vcard meta-text">Author: <a class="url fn n" href="%1$s">%2$s</a></li>', 'jester' ),
  111.     esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  112.     esc_html( get_the_author() )
  113.   );
  114.    
  115.   /* translators: used between list items, there is a space after the comma */
  116.   $categories_list = get_the_category_list( __( ', ', 'jester' ) );
  117.   if ( $categories_list && jester_categorized_blog() ) :
  118.     printf( __( '<li class="cat-links meta-text">Posted In: %s</li>', 'jester' ),
  119.       $categories_list
  120.     );
  121.   endif;
  122.    
  123.   /* translators: used between list items, there is a space after the comma */
  124.   $tags_list = get_the_tag_list( '', __( ', ', 'jester' ) );
  125.   if ( $tags_list ) :
  126.     printf( __( '<li class="tags-links meta-text">Tagged: %s</li>', 'jester' ),
  127.       $tags_list
  128.     );
  129.   endif;
  130.    
  131.   if ( ! is_single() && ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) :
  132.     echo '<li class="comments-link meta-text">';
  133.     comments_popup_link( __( 'Leave a comment', 'jester' ), __( '1 Comment', 'jester' ), __( '% Comments', 'jester' ) );
  134.     echo '</li>';
  135.   endif;
  136.    
  137.   edit_post_link( __( 'Edit', 'jester' ), '<li class="edit-link meta-text">', '</li>' );
  138. }
  139. endif;
  140.  
  141. /**
  142.  * Returns true if a blog has more than 1 category.
  143.  */
  144. function jester_categorized_blog() {
  145.     if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
  146.         // Create an array of all the categories that are attached to posts.
  147.         $all_the_cool_cats = get_categories( array(
  148.             'hide_empty' => 1,
  149.         ) );
  150.  
  151.         // Count the number of categories that are attached to the posts.
  152.         $all_the_cool_cats = count( $all_the_cool_cats );
  153.  
  154.         set_transient( 'all_the_cool_cats', $all_the_cool_cats );
  155.     }
  156.  
  157.     if ( '1' != $all_the_cool_cats ) {
  158.         // This blog has more than 1 category so jester_categorized_blog should return true.
  159.         return true;
  160.     } else {
  161.         // This blog has only 1 category so jester_categorized_blog should return false.
  162.         return false;
  163.     }
  164. }
  165.  
  166. /**
  167.  * Flush out the transients used in jester_categorized_blog.
  168.  */
  169. function jester_category_transient_flusher() {
  170.     // Like, beat it. Dig?
  171.     delete_transient( 'all_the_cool_cats' );
  172. }
  173. add_action( 'edit_category', 'jester_category_transient_flusher' );
  174. add_action( 'save_post',     'jester_category_transient_flusher' );
  175.  
  176. /**
  177.  * Custom function to list comments
  178.  */
  179. if ( ! function_exists( 'jester_list_comments' ) ) :
  180. function jester_list_comments( $comment, $args, $depth ) {
  181.   $GLOBALS['comment'] = $comment;
  182.     global $post;
  183.    
  184.     if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
  185.         <li id="div-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
  186.             <article class="comment-body">
  187.                 <header class="comment-meta">
  188.                     <cite><?php _e( 'Pingback:', 'jester' ); ?></cite>
  189.                
  190.                     <?php edit_comment_link( __( 'Edit', 'jester' ) ); ?>
  191.                 </header>
  192.                
  193.                 <section class="pingback-content">
  194.                     <?php comment_author_link(); ?>
  195.                 </section>
  196.             </article><!-- .comment-body -->
  197.         </li><!-- #comment-id -->
  198.     <?php else : ?>
  199.         <li <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
  200.           <article id="comment-<?php comment_ID(); ?>" class="comment-body">
  201.             <header class="comment-header">
  202.               <?php
  203.               if ( '0' != $args['avatar_size'] ) :
  204.                 echo get_avatar( $comment, $args['avatar_size'] );
  205.             endif;
  206.           ?>
  207.                    
  208.           <cite class="fn"><?php echo get_comment_author_link(); ?></cite>
  209.             </header>
  210.                
  211.         <div class="comment-content">
  212.               <?php
  213.               if ( '0' == $comment->comment_approved ) : ?>
  214.                 <p><?php _e( 'Your comment is awaiting moderation.', 'jester' ); ?></p>
  215.           <?php endif; ?>
  216.                
  217.               <p><?php comment_text(); ?></p>
  218.             </div>
  219.            
  220.             <footer class="comment-meta">
  221.               <ul>    
  222.                   <li class="comment-posted-on meta-text"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><time datetime="<?php comment_time( 'c' ); ?>"><?php printf( _x( '%1$s, %2$s', '1: date, 2: time', 'jester' ), get_comment_date() /* %1$s */, get_comment_time() /* %2$s */ ); ?></time></a></li>
  223.                  
  224.                 <?php edit_comment_link( __( 'Edit', 'jester' ), '<li class="comment-edit-link meta-text">', '</li>' ); ?>
  225.                
  226.                 <?php
  227.                 comment_reply_link( array_merge( $args, array(
  228.                   'add_below' => 'comment',
  229.                   'depth'     => $depth,
  230.                   'max_depth' => $args['max_depth'],
  231.                   'before'    => '<li class="comment-reply-link meta-text">',
  232.                   'after'     => '</li>'
  233.                 ) ) );
  234.                 ?>
  235.               </ul>
  236.             </footer>
  237.           </article>
  238.         </li>
  239.   <?php endif; ?>
  240. <?php
  241. }
  242. endif; // ends check for jester_list_comments()
  243. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement