template.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_on' ) ) :
  52. function dw_posted_on() {
  53. return sprintf( __( '<span %1$s></span> %2$s by %3$s', 'daw' ),
  54. 'class="meta-prep meta-prep-author"',
  55. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a> <span class="meta-sep">',
  56. get_permalink(),
  57. esc_attr( get_the_time() ),
  58. get_the_date()
  59. ),
  60. sprintf( '</span> <span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  61. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  62. sprintf( esc_attr__( 'View all posts by %s', 'daw' ), get_the_author() ),
  63. get_the_author()
  64. )
  65. );
  66. }
  67. endif;
  68. if ( ! function_exists( 'dw_posted_in' ) ) :
  69. function dw_posted_in() {
  70. $tag_list = get_the_tag_list( '', ', ', '' );
  71. if ( $tag_list ) {
  72. $utility_text = __( '%1$s and tagged %2$s. <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'dw' );
  73. } else {
  74. $utility_text = __( '%1$s. <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'dw' );
  75. }
  76. return sprintf(
  77. $utility_text,
  78. get_the_category_list( ', ' ),
  79. $tag_list,
  80. get_permalink(),
  81. the_title_attribute( 'echo=0' ),
  82. get_post_comments_feed_link()
  83. );
  84. }
  85. endif;
  86. if ( ! function_exists( 'dw_get_next_attachment_url' ) ) :
  87. function dw_get_next_attachment_url() {
  88. global $post;
  89. $post = get_post( $post );
  90. $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' ) ) );
  91. foreach ( $attachments as $k => $attachment ) {
  92. if ( $attachment->ID == $post->ID )
  93. break;
  94. }
  95. $k++;
  96. if ( isset( $attachments[ $k ] ) )
  97. return get_attachment_link( $attachments[ $k ]->ID );
  98. else
  99. return get_permalink( $post->post_parent );
  100. }
  101. endif;
  102. if ( ! function_exists( 'dw_post_nav' ) ) :
  103. function dw_post_nav() {
  104. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  105. $next = get_adjacent_post( false, '', false );
  106. if ( ! $next && ! $previous ) {
  107. return;
  108. }
  109. ?>
  110. <nav class="navigation post-navigation" role="navigation">
  111. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'dw' ); ?></h1>
  112. <div class="nav-links">
  113. <?php
  114. if ( is_attachment() ) :
  115. previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'dw' ) );
  116. else :
  117. previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'dw' ) );
  118. next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'dw' ) );
  119. endif;
  120. ?>
  121. </div>
  122. </nav>
  123. <?php
  124. }
  125. endif;
  126. if ( ! function_exists( 'dw_cat_list' ) ) :
  127. function dw_cat_list() {
  128. return daw_term_list( 'category', ', ', __( 'Posted in %s', 'dw' ), __( 'Also posted in %s', 'daw' ) );
  129. }
  130. endif;
  131. if ( ! function_exists( 'dw_tag_list' ) ) :
  132. function dw_tag_list() {
  133. return daw_term_list( 'post_tag', ', ', __( 'Tagged %s', 'dw' ), __( 'Also tagged %s', 'daw' ) );
  134. }
  135. endif;
  136. if ( ! function_exists( 'dw_term_list' ) ) :
  137. function daw_term_list( $taxonomy, $glue = ', ', $text = '', $also_text = '' ) {
  138. global $wp_query, $post;
  139. $current_term = $wp_query->get_queried_object();
  140. $terms = wp_get_object_terms( $post->ID, $taxonomy );
  141. if ( isset( $current_term->taxonomy ) && $taxonomy == $current_term->taxonomy ) {
  142. foreach ( (array) $terms as $key => $term ) {
  143. if ( $term->term_id == $current_term->term_id ) {
  144. unset( $terms[$key] );
  145. break;
  146. }
  147. }
  148. $text = $also_text;
  149. }
  150. $tlist = array();
  151. $rel = 'category' == $taxonomy ? 'rel="category"' : 'rel="tag"';
  152. foreach ( (array) $terms as $term ) {
  153. $tlist[] = '<a href="' . get_term_link( $term, $taxonomy ) . '" title="' . esc_attr( sprintf( __( 'View all posts in %s', 'daw' ), $term->name ) ) . '" ' . $rel . '>' . $term->name . '</a>';
  154. }
  155. if ( ! empty( $tlist ) )
  156. return sprintf( $text, join( $glue, $tlist ) );
  157. return '';
  158. }
  159. endif;
  160. if ( ! function_exists( 'dw_comment' ) ) :
  161. function dw_comment( $comment, $args, $depth ) {
  162. $GLOBALS ['comment'] = $comment; ?>
  163. <?php if ( '' == $comment->comment_type ) : ?>
  164. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  165. <div id="comment-<?php comment_ID(); ?>">
  166. <div class="comment-author vcard">
  167. <?php echo get_avatar( $comment, 40 ); ?>
  168. <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>', 'daw' ), get_comment_author_link() ); ?>
  169. </div>
  170. <?php if ( $comment->comment_approved == '0' ) : ?>
  171. <em><?php _e( 'Your comment is awaiting moderation.', 'daw' ); ?></em>
  172. <br />
  173. <?php endif; ?>
  174. <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>
  175. <div class="comment-body"><?php comment_text(); ?></div>
  176. <div class="reply">
  177. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  178. </div>
  179. </div>
  180. <?php else : ?>
  181. <li class="post pingback">
  182. <p><?php _e( 'Pingback: ', 'daw' ); ?><?php comment_author_link(); ?><?php edit_comment_link ( __('edit', 'daw'), '&nbsp;&nbsp;', '' ); ?></p>
  183. <?php endif;
  184. }
  185. endif;