template.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. if ( ! function_exists( 'dw_page_title') ) :
  3. function dw_page_title() {
  4. global $page, $paged;
  5. wp_title( '|', true, 'right' );
  6. bloginfo( 'name' ); $site_description = get_bloginfo( 'description', 'display' );
  7. if ( $site_description && ( is_home() || is_front_page() ) )
  8. echo " | $site_description";
  9. if ( $paged >= 2 || $page >= 2 )
  10. echo ' | ' . sprintf( __( 'Page %s', 'dw' ), max( $paged, $page ) );
  11. }
  12. endif;
  13. if ( ! function_exists( 'dw_paging_nav' ) ) :
  14. function dw_paging_nav() {
  15. if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  16. return;
  17. }
  18. $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  19. $pagenum_link = html_entity_decode( get_pagenum_link() );
  20. $query_args = array();
  21. $url_parts = explode( '?', $pagenum_link );
  22. if ( isset( $url_parts[1] ) ) {
  23. wp_parse_str( $url_parts[1], $query_args );
  24. }
  25. $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  26. $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  27. $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  28. $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
  29. $links = paginate_links( array(
  30. 'base' => $pagenum_link,
  31. 'format' => $format,
  32. 'total' => $GLOBALS['wp_query']->max_num_pages,
  33. 'current' => $paged,
  34. 'mid_size' => 1,
  35. 'add_args' => array_map( 'urlencode', $query_args ),
  36. 'prev_text' => __( '&larr; &nbsp;', 'dw' ),
  37. 'next_text' => __( '&nbsp; &rarr;', 'dw' ),
  38. ) );
  39. if ( $links ) :
  40. ?>
  41. <nav class="navigation paging-navigation" role="navigation">
  42. <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'dw' ); ?></h1>
  43. <div class="pagination loop-pagination">
  44. <?php echo $links; ?>
  45. </div>
  46. </nav>
  47. <?php
  48. endif;
  49. }
  50. endif;
  51. if ( ! function_exists( 'dw_posted_at' ) ) :
  52. function dw_posted_at() {
  53. $categories_list = get_the_category_list( __( ', ', 'dw' ) );
  54. if ( in_category( 'fb' )) {
  55. echo '<div class="categories-fb"><a href="http://facebook.com/windhamdavid" target="_blank">posted on <span class="fb">&nbsp;</span></a></div>';
  56. } elseif ( in_category( array( 'twitter', 'tumblr' ) )) {
  57. } else {
  58. echo '<span class="categories-links">' . $categories_list . '</span>';
  59. }
  60. }
  61. endif;
  62. if ( ! function_exists( 'dw_posted_on' ) ) :
  63. function dw_posted_on() {
  64. return sprintf( __( '<span %1$s></span> %2$s by %3$s', 'daw' ),
  65. 'class="meta-prep meta-prep-author"',
  66. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a> <span class="meta-sep">',
  67. get_permalink(),
  68. esc_attr( get_the_time() ),
  69. get_the_date()
  70. ),
  71. sprintf( '</span> <span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  72. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  73. sprintf( esc_attr__( 'View all posts by %s', 'daw' ), get_the_author() ),
  74. get_the_author()
  75. )
  76. );
  77. }
  78. endif;
  79. if ( ! function_exists( 'dw_posted_in' ) ) :
  80. function dw_posted_in() {
  81. $tag_list = get_the_tag_list( '', ', ', '' );
  82. if ( $tag_list ) {
  83. $utility_text = __( '%1$s and tagged %2$s. <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'dw' );
  84. } else {
  85. $utility_text = __( '%1$s. <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'dw' );
  86. }
  87. return sprintf(
  88. $utility_text,
  89. get_the_category_list( ', ' ),
  90. $tag_list,
  91. get_permalink(),
  92. the_title_attribute( 'echo=0' ),
  93. get_post_comments_feed_link()
  94. );
  95. }
  96. endif;
  97. if ( ! function_exists( 'dw_get_next_attachment_url' ) ) :
  98. function dw_get_next_attachment_url() {
  99. global $post;
  100. $post = get_post( $post );
  101. $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
  102. foreach ( $attachments as $k => $attachment ) {
  103. if ( $attachment->ID == $post->ID )
  104. break;
  105. }
  106. $k++;
  107. if ( isset( $attachments[ $k ] ) )
  108. return get_attachment_link( $attachments[ $k ]->ID );
  109. else
  110. return get_permalink( $post->post_parent );
  111. }
  112. endif;
  113. if ( ! function_exists( 'dw_post_nav' ) ) :
  114. function dw_post_nav() {
  115. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  116. $next = get_adjacent_post( false, '', false );
  117. if ( ! $next && ! $previous ) {
  118. return;
  119. }
  120. ?>
  121. <nav class="navigation post-navigation" role="navigation">
  122. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'dw' ); ?></h1>
  123. <div class="nav-links">
  124. <?php
  125. if ( is_attachment() ) :
  126. previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'dw' ) );
  127. else :
  128. previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'dw' ) );
  129. next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'dw' ) );
  130. endif;
  131. ?>
  132. </div>
  133. </nav>
  134. <?php
  135. }
  136. endif;
  137. if ( ! function_exists( 'dw_cat_list' ) ) :
  138. function dw_cat_list() {
  139. return daw_term_list( 'category', ', ', __( 'Posted in %s', 'dw' ), __( 'Also posted in %s', 'daw' ) );
  140. }
  141. endif;
  142. if ( ! function_exists( 'dw_tag_list' ) ) :
  143. function dw_tag_list() {
  144. return daw_term_list( 'post_tag', ', ', __( 'Tagged %s', 'dw' ), __( 'Also tagged %s', 'daw' ) );
  145. }
  146. endif;
  147. if ( ! function_exists( 'dw_term_list' ) ) :
  148. function daw_term_list( $taxonomy, $glue = ', ', $text = '', $also_text = '' ) {
  149. global $wp_query, $post;
  150. $current_term = $wp_query->get_queried_object();
  151. $terms = wp_get_object_terms( $post->ID, $taxonomy );
  152. if ( isset( $current_term->taxonomy ) && $taxonomy == $current_term->taxonomy ) {
  153. foreach ( (array) $terms as $key => $term ) {
  154. if ( $term->term_id == $current_term->term_id ) {
  155. unset( $terms[$key] );
  156. break;
  157. }
  158. }
  159. $text = $also_text;
  160. }
  161. $tlist = array();
  162. $rel = 'category' == $taxonomy ? 'rel="category"' : 'rel="tag"';
  163. foreach ( (array) $terms as $term ) {
  164. $tlist[] = '<a href="' . get_term_link( $term, $taxonomy ) . '" title="' . esc_attr( sprintf( __( 'View all posts in %s', 'daw' ), $term->name ) ) . '" ' . $rel . '>' . $term->name . '</a>';
  165. }
  166. if ( ! empty( $tlist ) )
  167. return sprintf( $text, join( $glue, $tlist ) );
  168. return '';
  169. }
  170. endif;
  171. if ( ! function_exists( 'dw_comment' ) ) :
  172. function dw_comment( $comment, $args, $depth ) {
  173. $GLOBALS ['comment'] = $comment; ?>
  174. <?php if ( '' == $comment->comment_type ) : ?>
  175. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  176. <div id="comment-<?php comment_ID(); ?>">
  177. <div class="comment-author vcard">
  178. <?php echo get_avatar( $comment, 16 ); ?>
  179. <?php printf( __( '<cite class="fn">%s</cite><span class="says">:</span>', 'daw' ), get_comment_author_link() ); ?>
  180. </div>
  181. <?php if ( $comment->comment_approved == '0' ) : ?>
  182. <em><?php _e( 'Your comment is awaiting moderation.', 'daw' ); ?></em>
  183. <br />
  184. <?php endif; ?>
  185. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php printf( __( '%1$s at %2$s', 'daw' ), get_comment_date(), get_comment_time() ); ?></a></div>
  186. <div class="comment-body"><?php comment_text(); ?></div>
  187. <div class="reply">
  188. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  189. <?php edit_comment_link( __( '(Edit)', 'daw' ),' ','' ); ?>
  190. </div>
  191. </div>
  192. <?php else : ?>
  193. <li class="post pingback">
  194. <p><?php _e( 'Pingback: ', 'daw' ); ?><?php comment_author_link(); ?><?php edit_comment_link ( __('edit', 'daw'), '&nbsp;&nbsp;', '' ); ?></p>
  195. <?php endif;
  196. }
  197. endif;