template.php 6.6 KB

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