/includes/mh-custom-functions.php

  1. <?php 
  2.  
  3. /***** Logo/Sitename *****/ 
  4.  
  5. if (!function_exists('mh_newsdesk_lite_logo')) { 
  6. function mh_newsdesk_lite_logo() { 
  7. $header_img = get_header_image(); 
  8. $header_title = get_bloginfo('name'); 
  9. $header_desc = get_bloginfo('description'); 
  10. echo '<a href="' . esc_url(home_url('/')) . '" title="' . esc_attr($header_title) . '" rel="home">' . "\n"; 
  11. echo '<div class="logo-wrap" role="banner">' . "\n"; 
  12. if ($header_img) { 
  13. echo '<img src="' . esc_url($header_img) . '" height="' . get_custom_header()->height . '" width="' . get_custom_header()->width . '" alt="' . esc_attr($header_title) . '" />' . "\n"; 
  14. if (display_header_text()) { 
  15. $text_color = get_header_textcolor(); 
  16. if ($text_color != get_theme_support('custom-header', 'default-text-color')) { 
  17. echo '<style type="text/css" id="mh-header-css">'; 
  18. echo '.logo-title, .logo-tagline { color: #' . esc_attr($text_color) . '; }'; 
  19. echo '</style>' . "\n"; 
  20. echo '<div class="logo">' . "\n"; 
  21. if ($header_title) { 
  22. echo '<h1 class="logo-title">' . esc_attr($header_title) . '</h1>' . "\n"; 
  23. if ($header_desc) { 
  24. echo '<h2 class="logo-tagline">' . esc_attr($header_desc) . '</h2>' . "\n"; 
  25. echo '</div>' . "\n"; 
  26. echo '</div>' . "\n"; 
  27. echo '</a>' . "\n"; 
  28.  
  29. /***** Page Title Output *****/ 
  30.  
  31. if (!function_exists('mh_newsdesk_lite_page_title')) { 
  32. function mh_newsdesk_lite_page_title() { 
  33. if (!is_front_page()) { 
  34. echo '<h1 class="page-title">'; 
  35. if (is_archive()) { 
  36. if (is_category() || is_tax()) { 
  37. single_cat_title(); 
  38. } elseif (is_tag()) { 
  39. single_tag_title(); 
  40. } elseif (is_author()) { 
  41. global $author; 
  42. $user_info = get_userdata($author); 
  43. printf(_x('Articles by %s', 'post author', 'mh-newsdesk-lite'), esc_attr($user_info->display_name)); 
  44. } elseif (is_day()) { 
  45. echo get_the_date(); 
  46. } elseif (is_month()) { 
  47. echo get_the_date('F Y'); 
  48. } elseif (is_year()) { 
  49. echo get_the_date('Y'); 
  50. } elseif (is_post_type_archive()) { 
  51. global $post; 
  52. $post_type = get_post_type_object(get_post_type($post)); 
  53. echo $post_type->labels->name; 
  54. } else { 
  55. _e('Archives', 'mh-newsdesk-lite'); 
  56. } else { 
  57. if (is_home()) { 
  58. echo get_the_title(get_option('page_for_posts', true)); 
  59. } elseif (is_404()) { 
  60. _e('Page not found (404)', 'mh-newsdesk-lite'); 
  61. } elseif (is_search()) { 
  62. printf(__('Search Results for %s', 'mh-newsdesk-lite'), esc_attr(get_search_query())); 
  63. } else { 
  64. the_title(); 
  65. echo '</h1>' . "\n"; 
  66.  
  67. /***** Output Post Meta Data *****/ 
  68.  
  69. if (!function_exists('mh_newsdesk_lite_post_meta')) { 
  70. function mh_newsdesk_lite_post_meta() { 
  71. echo '<p class="entry-meta">' . "\n"; 
  72. if (has_category() && !is_single()) { 
  73. echo '<span class="entry-meta-cats">' . get_the_category_list(', ', '') . '</span>' . "\n"; 
  74. if (is_single()) { 
  75. echo '<span class="entry-meta-author vcard author">' . sprintf(_x('Posted By: %s', 'post author', 'mh-newsdesk-lite'), '<a class="fn" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a>') . '</span>' . "\n"; 
  76. echo '<span class="entry-meta-date updated">' . get_the_date() . '</span>' . "\n"; 
  77. echo '</p>' . "\n"; 
  78.  
  79. /***** Featured Image on Posts *****/ 
  80.  
  81. if (!function_exists('mh_newsdesk_lite_featured_image')) { 
  82. function mh_newsdesk_lite_featured_image() { 
  83. global $page, $post; 
  84. if (has_post_thumbnail() && $page == '1') { 
  85. $caption_text = get_post(get_post_thumbnail_id())->post_excerpt; 
  86. echo "\n" . '<div class="entry-thumbnail">' . "\n"; 
  87. the_post_thumbnail('content-single'); 
  88. if ($caption_text) { 
  89. echo '<span class="wp-caption-text">' . wp_kses_post($caption_text) . '</span>' . "\n"; 
  90. echo '</div>' . "\n"; 
  91.  
  92. /***** Custom Excerpts *****/ 
  93.  
  94. if (!function_exists('mh_newsdesk_lite_trim_excerpt')) { 
  95. function mh_newsdesk_lite_trim_excerpt($text = '') { 
  96. $raw_excerpt = $text; 
  97. if ('' == $text) { 
  98. $mh_newsdesk_lite_lite_options = mh_newsdesk_lite_theme_options(); 
  99. $text = get_the_content(''); 
  100. $text = strip_shortcodes($text); 
  101. $text = apply_filters('the_content', $text); 
  102. $text = str_replace(']]>', ']]>', $text); 
  103. $excerpt_length = apply_filters('excerpt_length', $mh_newsdesk_lite_lite_options['excerpt_length']); 
  104. $excerpt_more = apply_filters('excerpt_more', '...'); 
  105. $text = wp_trim_words($text, $excerpt_length, $excerpt_more); 
  106. return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); 
  107. remove_filter('get_the_excerpt', 'wp_trim_excerpt'); 
  108. add_filter('get_the_excerpt', 'mh_newsdesk_lite_trim_excerpt'); 
  109.  
  110. /***** Pagination *****/ 
  111.  
  112. if (!function_exists('mh_newsdesk_lite_pagination')) { 
  113. function mh_newsdesk_lite_pagination() { 
  114. if (get_the_posts_pagination()) { 
  115. echo '<div class="mh-loop-pagination clearfix">'; 
  116. the_posts_pagination(array( 
  117. 'mid_size' => 1,  
  118. 'prev_text' => esc_html__('«', 'mh-newsdesk-lite'),  
  119. 'next_text' => esc_html__('»', 'mh-newsdesk-lite'),  
  120. )); 
  121. echo '</div>'; 
  122.  
  123. /***** Pagination for paginated Posts *****/ 
  124.  
  125. if (!function_exists('mh_newsdesk_lite_posts_pagination')) { 
  126. function mh_newsdesk_lite_posts_pagination($content) { 
  127. if (is_singular() && is_main_query()) { 
  128. $content .= wp_link_pages(array('before' => '<div class="pagination clear">', 'after' => '</div>', 'link_before' => '<span class="pagelink">', 'link_after' => '</span>', 'nextpagelink' => __('»', 'mh-newsdesk-lite'), 'previouspagelink' => __('«', 'mh-newsdesk-lite'), 'pagelink' => '%', 'echo' => 0)); 
  129. return $content; 
  130. add_filter('the_content', 'mh_newsdesk_lite_posts_pagination', 1); 
  131.  
  132. /***** Post / Image Navigation *****/ 
  133.  
  134. if (!function_exists('mh_newsdesk_lite_postnav')) { 
  135. function mh_newsdesk_lite_postnav() { 
  136. global $post; 
  137. $parent_post = get_post($post->post_parent); 
  138. $attachment = is_attachment(); 
  139. $previous = ($attachment) ? $parent_post : get_adjacent_post(false, '', true); 
  140. $next = get_adjacent_post(false, '', false); 
  141.  
  142. if (!$next && !$previous) 
  143. return; 
  144.  
  145. if ($attachment) { 
  146. $attachments = get_children(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $parent_post->ID)); 
  147. $count = count($attachments); 
  148. echo '<nav class="post-nav-wrap" role="navigation">' . "\n"; 
  149. echo '<ul class="post-nav clearfix">' . "\n"; 
  150. echo '<li class="post-nav-prev">' . "\n"; 
  151. if ($attachment) { 
  152. if ($count == 1) { 
  153. $permalink = get_permalink($parent_post); 
  154. echo '<a href="' . $permalink . '"><i class="fa fa-chevron-left"></i>' . __('Back to post', 'mh-newsdesk-lite') . '</a>'; 
  155. } else { 
  156. previous_image_link('%link', '<i class="fa fa-chevron-left"></i>' . __('Previous image', 'mh-newsdesk-lite')); 
  157. } else { 
  158. previous_post_link('%link', '<i class="fa fa-chevron-left"></i>' . __('Previous post', 'mh-newsdesk-lite')); 
  159. echo '</li>' . "\n"; 
  160. echo '<li class="post-nav-next">' . "\n"; 
  161. if ($attachment) { 
  162. next_image_link('%link', __('Next image', 'mh-newsdesk-lite') . '<i class="fa fa-chevron-right"></i>'); 
  163. } else { 
  164. next_post_link('%link', __('Next post', 'mh-newsdesk-lite') . '<i class="fa fa-chevron-right"></i>'); 
  165. echo '</li>' . "\n"; 
  166. echo '</ul>' . "\n"; 
  167. echo '</nav>' . "\n"; 
  168.  
  169. /***** Custom Commentlist *****/ 
  170.  
  171. if (!function_exists('mh_newsdesk_lite_comments')) { 
  172. function mh_newsdesk_lite_comments($comment, $args, $depth) { 
  173. $GLOBALS['comment'] = $comment; ?> 
  174. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>"> 
  175. <div id="comment-<?php comment_ID(); ?>"> 
  176. <div class="vcard meta"> 
  177. <?php echo get_avatar($comment->comment_author_email, 70); ?> 
  178. <?php echo get_comment_author_link() ?> | 
  179. <a href="<?php echo esc_url(get_comment_link($comment->comment_ID)) ?>"><?php printf(__('%1$s at %2$s', 'mh-newsdesk-lite'), get_comment_date(), get_comment_time()) ?></a> | 
  180. <?php if (comments_open() && $args['max_depth']!=$depth) { ?> 
  181. <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> 
  182. <?php } ?> 
  183. <?php edit_comment_link(__('(Edit)', 'mh-newsdesk-lite'), ' ', '') ?> 
  184. </div> 
  185. <?php if ($comment->comment_approved == '0') : ?> 
  186. <div class="comment-info"><?php _e('Your comment is awaiting moderation.', 'mh-newsdesk-lite') ?></div> 
  187. <?php endif; ?> 
  188. <div class="comment-text"> 
  189. <?php comment_text() ?> 
  190. </div> 
  191. </div><?php 
  192.  
  193. /***** Custom Comment Fields *****/ 
  194.  
  195. if (!function_exists('mh_newsdesk_lite_comment_fields')) { 
  196. function mh_newsdesk_lite_comment_fields($fields) { 
  197. $commenter = wp_get_current_commenter(); 
  198. $req = get_option('require_name_email'); 
  199. $aria_req = ($req ? " aria-required='true'" : ''); 
  200. $fields = array( 
  201. 'author' => '<p class="comment-form-author"><label for="author">' . __('Name ', 'mh-newsdesk-lite') . '</label>' . ($req ? '<span class="required">*</span>' : '') . '<br/><input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30"' . $aria_req . ' /></p>',  
  202. 'email' => '<p class="comment-form-email"><label for="email">' . __('Email ', 'mh-newsdesk-lite') . '</label>' . ($req ? '<span class="required">*</span>' : '' ) . '<br/><input id="email" name="email" type="text" value="' . esc_attr($commenter['comment_author_email']) . '" size="30"' . $aria_req . ' /></p>',  
  203. 'url' => '<p class="comment-form-url"><label for="url">' . __('Website', 'mh-newsdesk-lite') . '</label><br/><input id="url" name="url" type="text" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" /></p>' 
  204. ); 
  205. return $fields; 
  206. add_filter('comment_form_default_fields', 'mh_newsdesk_lite_comment_fields'); 
  207.  
  208. /***** Read More Button *****/ 
  209.  
  210. function mh_newsdesk_lite_more() { 
  211. $mh_newsdesk_lite_lite_options = mh_newsdesk_lite_theme_options(); ?> 
  212. <a class="button" href="<?php the_permalink(); ?>"> 
  213. <span><?php echo esc_attr($mh_newsdesk_lite_lite_options['excerpt_more']); ?></span> 
  214. </a><?php 
  215.  
  216. /***** Add CSS classes to body tag *****/ 
  217.  
  218. if (!function_exists('mh_newsdesk_lite_body_class')) { 
  219. function mh_newsdesk_lite_body_class($classes) { 
  220. $mh_newsdesk_lite_lite_options = mh_newsdesk_lite_theme_options(); 
  221. $classes[] = 'mh-' . $mh_newsdesk_lite_lite_options['sidebar'] . '-sb'; 
  222. return $classes; 
  223. add_filter('body_class', 'mh_newsdesk_lite_body_class'); 
  224.  
  225. /***** Add CSS3 Media Queries Support for older versions of IE *****/ 
  226.  
  227. function mh_newsdesk_lite_ie_media_queries() { 
  228. echo '<!--[if lt IE 9]>' . "\n"; 
  229. echo '<script src="' . get_template_directory_uri() . '/js/css3-mediaqueries.js"></script>' . "\n"; 
  230. echo '<![endif]-->' . "\n"; 
  231. add_action('wp_head', 'mh_newsdesk_lite_ie_media_queries'); 
  232.  
  233. ?> 
.