template.php 13 KB

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