template.php 12 KB

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