template.php 11 KB

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