template.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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_meta_desc') ) :
  14. function dw_meta_desc() {
  15. global $post;
  16. $post = get_post( $post );
  17. setup_postdata( $post );
  18. if ( is_single() || is_page() ) {
  19. $meta_desc_value = get_post_meta( $post->ID, 'meta-desc', true );
  20. if ( $meta_desc_value !== '') {
  21. echo $meta_desc_value;
  22. }
  23. elseif ( $meta_desc_value == '') {
  24. $meta_excerpt = dw_good_excerpt(115);
  25. echo $meta_excerpt;
  26. }
  27. }
  28. }
  29. endif;
  30. if ( ! function_exists( 'dw_good_excerpt') ) :
  31. function dw_good_excerpt($length) {
  32. global $post;
  33. $text = $post->post_excerpt;
  34. if ( '' == $text ) {
  35. $text = get_the_content('');
  36. $text = apply_filters('the_content', $text);
  37. $text = str_replace(']]>', ']]>', $text);
  38. }
  39. $text = strip_shortcodes($text);
  40. $text = strip_tags($text);
  41. $text = substr($text,0,$length);
  42. if ( strlen($text) < 15 ) {
  43. $text = the_title('', ' - ', false);
  44. }
  45. $allowed_end = array('.', '!', '?', '...');
  46. $excerpt = reverse_strrchr($text, '.', 2);
  47. if( $excerpt ) {
  48. echo apply_filters('get_the_excerpt',$excerpt);
  49. } else {
  50. echo apply_filters('get_the_excerpt',$text);
  51. }
  52. }
  53. function reverse_strrchr($haystack, $needle, $trail) {
  54. return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) + $trail) : false;
  55. }
  56. endif;
  57. if ( ! function_exists( 'dw_excerpt') ) :
  58. function dw_excerpt($count){
  59. $permalink = get_permalink($post->ID);
  60. $excerpt = get_the_content();
  61. $excerpt = strip_tags($excerpt);
  62. $excerpt = substr($excerpt, 0, $count);
  63. $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
  64. return $excerpt;
  65. }
  66. endif;
  67. if ( ! function_exists( 'dw_paging_nav' ) ) :
  68. function dw_paging_nav() {
  69. if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  70. return;
  71. }
  72. $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  73. $pagenum_link = html_entity_decode( get_pagenum_link() );
  74. $query_args = array();
  75. $url_parts = explode( '?', $pagenum_link );
  76. if ( isset( $url_parts[1] ) ) {
  77. wp_parse_str( $url_parts[1], $query_args );
  78. }
  79. $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  80. $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  81. $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  82. $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
  83. $links = paginate_links( array(
  84. 'base' => $pagenum_link,
  85. 'format' => $format,
  86. 'total' => $GLOBALS['wp_query']->max_num_pages,
  87. 'current' => $paged,
  88. 'mid_size' => 1,
  89. 'add_args' => array_map( 'urlencode', $query_args ),
  90. 'prev_text' => __( '&larr; &nbsp;', 'dw' ),
  91. 'next_text' => __( '&nbsp; &rarr;', 'dw' ),
  92. ) );
  93. if ( $links ) :
  94. ?>
  95. <nav class="navigation pagination paging-navigation" role="navigation">
  96. <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'dw' ); ?></h1>
  97. <div class="pagination loop-pagination">
  98. <?php echo $links; ?>
  99. </div>
  100. </nav>
  101. <?php
  102. endif;
  103. }
  104. endif;
  105. if ( ! function_exists( 'dw_posted_at' ) ) :
  106. function dw_posted_at() {
  107. $categories_list = get_the_category_list( __( ', ', 'dw' ) );
  108. if ( in_category( 'fb' )) {
  109. echo '<div class="categories-fb"><a href="http://facebook.com/windhamdavid" target="_blank">posted on <span class="fb">&nbsp;</span></a></div>';
  110. } elseif ( in_category( array( 'twitter', 'tumblr' ) )) {
  111. } else {
  112. echo '<span class="categories-links">' . $categories_list . '</span>';
  113. }
  114. }
  115. endif;
  116. if ( ! function_exists( 'dw_posted_on' ) ) :
  117. function dw_posted_on() {
  118. return sprintf( __( '<span %1$s></span> %2$s by %3$s', 'daw' ),
  119. 'class="meta-prep meta-prep-author"',
  120. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a> <span class="meta-sep">',
  121. get_permalink(),
  122. esc_attr( get_the_time() ),
  123. get_the_date()
  124. ),
  125. sprintf( '</span> <span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  126. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  127. sprintf( esc_attr__( 'View all posts by %s', 'daw' ), get_the_author() ),
  128. get_the_author()
  129. )
  130. );
  131. }
  132. endif;
  133. if ( ! function_exists( 'dw_posted_in' ) ) :
  134. function dw_posted_in() {
  135. $tag_list = get_the_tag_list( '', ', ', '' );
  136. if ( $tag_list ) {
  137. $utility_text = __( '%1$s and tagged %2$s. <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'dw' );
  138. } else {
  139. $utility_text = __( '%1$s. <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'dw' );
  140. }
  141. return sprintf(
  142. $utility_text,
  143. get_the_category_list( ', ' ),
  144. $tag_list,
  145. get_permalink(),
  146. the_title_attribute( 'echo=0' ),
  147. get_post_comments_feed_link()
  148. );
  149. }
  150. endif;
  151. if ( ! function_exists( 'dw_get_next_attachment_url' ) ) :
  152. function dw_get_next_attachment_url() {
  153. global $post;
  154. $post = get_post( $post );
  155. $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' ) ) );
  156. foreach ( $attachments as $k => $attachment ) {
  157. if ( $attachment->ID == $post->ID )
  158. break;
  159. }
  160. $k++;
  161. if ( isset( $attachments[ $k ] ) )
  162. return get_attachment_link( $attachments[ $k ]->ID );
  163. else
  164. return get_permalink( $post->post_parent );
  165. }
  166. endif;
  167. if ( ! function_exists( 'dw_post_nav' ) ) :
  168. function dw_post_nav() {
  169. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  170. $next = get_adjacent_post( false, '', false );
  171. if ( ! $next && ! $previous ) {
  172. return;
  173. }
  174. ?>
  175. <nav class="navigation post-navigation" role="navigation">
  176. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'dw' ); ?></h1>
  177. <div class="nav-links">
  178. <?php
  179. if ( is_attachment() ) :
  180. previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'dw' ) );
  181. else :
  182. previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'dw' ) );
  183. next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'dw' ) );
  184. endif;
  185. ?>
  186. </div>
  187. </nav>
  188. <?php
  189. }
  190. endif;
  191. if ( ! function_exists( 'dw_cat_list' ) ) :
  192. function dw_cat_list() {
  193. return daw_term_list( 'category', ', ', __( 'Posted in %s', 'dw' ), __( 'Also posted in %s', 'daw' ) );
  194. }
  195. endif;
  196. if ( ! function_exists( 'dw_tag_list' ) ) :
  197. function dw_tag_list() {
  198. return daw_term_list( 'post_tag', ', ', __( 'Tagged %s', 'dw' ), __( 'Also tagged %s', 'daw' ) );
  199. }
  200. endif;
  201. if ( ! function_exists( 'dw_term_list' ) ) :
  202. function daw_term_list( $taxonomy, $glue = ', ', $text = '', $also_text = '' ) {
  203. global $wp_query, $post;
  204. $current_term = $wp_query->get_queried_object();
  205. $terms = wp_get_object_terms( $post->ID, $taxonomy );
  206. if ( isset( $current_term->taxonomy ) && $taxonomy == $current_term->taxonomy ) {
  207. foreach ( (array) $terms as $key => $term ) {
  208. if ( $term->term_id == $current_term->term_id ) {
  209. unset( $terms[$key] );
  210. break;
  211. }
  212. }
  213. $text = $also_text;
  214. }
  215. $tlist = array();
  216. $rel = 'category' == $taxonomy ? 'rel="category"' : 'rel="tag"';
  217. foreach ( (array) $terms as $term ) {
  218. $tlist[] = '<a href="' . get_term_link( $term, $taxonomy ) . '" title="' . esc_attr( sprintf( __( 'View all posts in %s', 'daw' ), $term->name ) ) . '" ' . $rel . '>' . $term->name . '</a>';
  219. }
  220. if ( ! empty( $tlist ) )
  221. return sprintf( $text, join( $glue, $tlist ) );
  222. return '';
  223. }
  224. endif;
  225. if ( ! function_exists( 'dw_comment' ) ) :
  226. function dw_comment( $comment, $args, $depth ) {
  227. $GLOBALS ['comment'] = $comment; ?>
  228. <?php if ( '' == $comment->comment_type ) : ?>
  229. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  230. <div id="comment-<?php comment_ID(); ?>">
  231. <div class="comment-author vcard">
  232. <?php echo get_avatar( $comment, 64 ); ?>
  233. <?php printf( __( '<cite class="fn">%s</cite><span class="says">:</span>', 'daw' ), get_comment_author_link() ); ?>
  234. </div>
  235. <?php if ( $comment->comment_approved == '0' ) : ?>
  236. <em><?php _e( 'Your comment is awaiting moderation.', 'daw' ); ?></em>
  237. <br />
  238. <?php endif; ?>
  239. <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>
  240. <div class="comment-body"><?php comment_text(); ?></div>
  241. <div class="reply">
  242. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  243. <?php edit_comment_link( __( '(Edit)', 'daw' ),' ','' ); ?>
  244. </div>
  245. </div>
  246. <?php else : ?>
  247. <li class="post pingback">
  248. <p><?php _e( 'Pingback: ', 'daw' ); ?><?php comment_author_link(); ?><?php edit_comment_link ( __('edit', 'daw'), '&nbsp;&nbsp;', '' ); ?></p>
  249. <?php endif;
  250. }
  251. endif;
  252. add_filter( 'comment_form_default_fields', 'dw_comment_form_fields' );
  253. function dw_comment_form_fields( $fields ) {
  254. $commenter = wp_get_current_commenter();
  255. $req = get_option( 'require_name_email' );
  256. $aria_req = ( $req ? " aria-required='true'" : '' );
  257. $html5 = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;
  258. $fields = array(
  259. 'author' => '<div class="form-group comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
  260. '<div class="input-group"><div class="input-group-addon"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></div><input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /><span class="add-on"><i class="icon-user"></i></span></div></div>',
  261. 'email' => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
  262. '<div class="input-group"><div class="input-group-addon"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span></div><input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div></div>',
  263. 'url' => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
  264. '<div class="input-group"><div class="input-group-addon"><span class="glyphicon glyphicon-link" aria-hidden="true"></span></div><input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div></div>',
  265. );
  266. return $fields;
  267. }
  268. add_filter( 'comment_form_defaults', 'dw_comment_form' );
  269. function dw_comment_form( $args ) {
  270. $args['comment_field'] = '<div class="form-group comment-form-comment">
  271. <label for="comment">' . _x( 'Comment', 'noun' ) . '</label>
  272. <textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
  273. </div>';
  274. return $args;
  275. }
  276. add_action('comment_form', 'dw_comment_button' );
  277. function dw_comment_button() {
  278. echo '<button class="btn btn-default" type="submit">' . __( 'Submit' ) . '</button>';
  279. }