Advertisement
Uranbold

theme_functions.php

Apr 13th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.63 KB | None | 0 0
  1. <?php
  2. function ever_option($index, $default = ''){
  3. global $ever_redux;
  4. if ( isset( $ever_redux[ $index ]) ) {
  5. return $ever_redux[$index];
  6. } else {
  7. return $default;
  8. }
  9. }
  10. function ever_metabox($index, $default = ''){
  11. global $post;
  12. $metabox = !empty($post->ID) ? get_post_meta( $post->ID, EVER_META, true ) : '';
  13. if ( isset( $metabox[ $index ]) ) {
  14. return $metabox[$index];
  15. } else {
  16. return $default;
  17. }
  18. }
  19. function ever_metaboxes(){
  20. global $post;
  21. if ($post) {
  22. return get_post_meta( $post->ID, EVER_META, true );
  23. }
  24. return false;
  25. }
  26. function ever_favicon() {
  27. if(!function_exists('wp_site_icon') || !has_site_icon()){
  28. $fav = ever_option('favicon');
  29. if (!empty($fav['url'])) {
  30. $favicon = $fav['url'];
  31. } else {
  32. $favicon = EVER_DIR . 'assets/img/favicon.png';
  33. }
  34. echo '<link rel="shortcut icon" href="' . esc_url($favicon) . '" />' . "\n";
  35. }
  36. }
  37.  
  38. // Print menu
  39. //=======================================================
  40. function ever_menu() {
  41. wp_nav_menu(array(
  42. 'container' => false,
  43. 'menu_id' => '',
  44. 'menu_class' => 'sf-menu',
  45. 'fallback_cb' => 'ever_nomenu',
  46. 'theme_location' => 'main'
  47. ));
  48. }
  49. function ever_footer_menu() {
  50. wp_nav_menu(array(
  51. 'container' => 'div',
  52. 'container_class' => 'footer-menu',
  53. 'menu_id' => '',
  54. 'menu_class' => '',
  55. 'fallback_cb' => '',
  56. 'theme_location' => 'footer',
  57. 'depth' => '1'
  58. ));
  59. }
  60.  
  61. function ever_nomenu() {
  62. echo "<ul class='sf-menu'>";
  63. $howmany = 5;
  64. $pages=wp_list_pages(array('title_li'=>'','echo'=>0));
  65. preg_match_all('/(<li.*?>)(.*?)<\/li>/i', $pages, $matches);
  66. if(!empty($matches[0])){echo implode("\n", array_slice($matches[0],0,5));}
  67. echo "</ul>";
  68. }
  69. function ever_mobilemenu($loc = 'main') {
  70. wp_nav_menu(array(
  71. 'container' => false,
  72. 'menu_id' => '',
  73. 'menu_class' => 'sf-mobile-menu clearfix',
  74. 'fallback_cb' => 'ever_nomobile',
  75. 'theme_location' => $loc)
  76. );
  77. }
  78.  
  79. function ever_nomobile() {
  80. echo "<ul class='clearfix'>";
  81. wp_list_pages(array('title_li' => ''));
  82. echo "</ul>";
  83. }
  84.  
  85.  
  86. // Print logo
  87. //=======================================================
  88. function ever_logo($mobile = false) {
  89. $description = get_bloginfo( 'description', 'display' );
  90. $logo = ever_option("logo");
  91. $output = '<div class="tw-logo">';
  92. if ( !empty($logo['url']) ) {
  93. $output .= '<a class="logo" href="' . esc_url(home_url('/')) . '">';
  94. $output .= '<img class="logo-img" src="' . esc_url($logo['url']) . '" alt="' . esc_attr(get_bloginfo('name')) . '"/>';
  95. $output .= '</a>';
  96. } else {
  97. $output .= '<h1 class="site-name"><a class="logo" href="' . esc_url(home_url('/')) . '">';
  98. $output .= get_bloginfo('name');
  99. $output .= '</a></h1>';
  100.  
  101. if ( $description ){
  102. $output .= '<span class="site-description">'. $description .'</span>';
  103. }
  104. }
  105. if($mobile){
  106. $output .= '<div class="nav-icon-container"><div class="nav-icon tw-mdl-close active"><span></span><span></span><span></span></div></div>';
  107. }
  108. $output .= '</div>';
  109. return $output;
  110. }
  111. // ThemeWaves Pagination
  112. //=======================================================
  113. function ever_pagination($type = 'simple') {
  114. global $wp_query;
  115. $pages = intval($wp_query->max_num_pages);
  116. $paged = (get_query_var('paged')) ? intval(get_query_var('paged')) : 1;
  117. if (empty($pages)) {
  118. $pages = 1;
  119. }
  120. if($type == 'simple' && 1 != $pages){
  121. echo '<div class="tw-pagination tw-nextprev-link">';
  122. echo '<div class="newer">';
  123. previous_posts_link('<span><i class="ion-chevron-left"></i>'.ever_option('text_newer', esc_html__( 'Newer Posts', 'ever')).'</span>');
  124. echo '</div><div class="older">';
  125. next_posts_link('<span>'.ever_option('text_older', esc_html__( 'Older Posts', 'ever')).'<i class="ion-chevron-right"></i></span>' );
  126. echo '</div>';
  127. echo '</div>';
  128. }elseif($type == 'number' && 1 != $pages){
  129. $big = 9999; // need an unlikely integer
  130. echo "<div class='tw-pagination'>";
  131. $pagination = paginate_links(
  132. array(
  133. 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
  134. 'end_size' => 3,
  135. 'mid_size' => 6,
  136. 'format' => '?paged=%#%',
  137. 'current' => max(1, get_query_var('paged')),
  138. 'total' => $wp_query->max_num_pages,
  139. 'type' => 'list',
  140. 'prev_text' => '<i class="ion-chevron-left"></i>'.ever_option('text_prev', esc_html__( 'Prev', 'ever')),
  141. 'next_text' => ever_option('text_next', esc_html__( 'Next', 'ever')).'<i class="ion-chevron-right"></i>',
  142. )
  143. );
  144. echo balanceTags($pagination);
  145. echo "</div>";
  146. }elseif($type == 'infinite' && 1 != $pages){
  147. wp_enqueue_script('waypoints');
  148. echo '<div class="tw-pagination tw-infinite-scroll" data-has-next="' . ($paged === $pages ? 'false' : 'true') . '">';
  149. echo '<div class="loading"><div class="infinte-loader"></div></div>';
  150. echo '<div class="older"><a class="next" href="' . esc_url(get_pagenum_link($paged + 1)) . '"><span>'.ever_option('text_loadmore', esc_html__( 'More Stories', 'ever')).'</span></a></div>';
  151. echo '</div>';
  152. }
  153. }
  154.  
  155. function ever_get_image_by_id($id,$url=false,$size='full'){
  156. $lrg_img=wp_get_attachment_image_src($id,$size);
  157. $output='';
  158. if(isset($lrg_img[0])){
  159. if($url){
  160. $output.=$lrg_img[0];
  161. }else{
  162. $output.='<img src="'.esc_url($lrg_img[0]).'" />';
  163. }
  164. }
  165. return $output;
  166. }
  167.  
  168. if (!function_exists('ever_image')) {
  169. function ever_image($size = 'full', $returnURL = false) {
  170. global $post;
  171. $attachment = get_post(get_post_thumbnail_id($post->ID));
  172. if(!empty($attachment)){
  173. if ($returnURL) {
  174. $lrg_img = wp_get_attachment_image_src($attachment->ID, $size);
  175. $url = $lrg_img[0];
  176. $alt0 = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
  177. $alt = empty($alt0)?$attachment->post_title:$alt0;
  178. $img['url'] = $url;
  179. $img['alt'] = $alt;
  180. return $img;
  181. } else {
  182. return get_the_post_thumbnail($post->ID,$size);
  183. }
  184. }
  185. }
  186. }
  187.  
  188. if (!function_exists('ever_single_title')) {
  189. function ever_single_title(){
  190. if(ever_option('single_cats', true)){
  191. echo '<div class="entry-cats">'.ever_cats().'</div>';
  192. }
  193. echo '<h1 class="entry-title">'.get_the_title().'</h1>';
  194. if(ever_option('single_meta', true)){
  195. echo '<div class="tw-meta"><span class="entry-author">'.esc_html__('by', 'ever').'&nbsp;';
  196. the_author_posts_link();
  197. echo '</span><span class="entry-date"><a href="'.esc_url(get_permalink()).'">'.get_the_time(get_option('date_format')).'</a></span>';
  198. echo ever_comment_count();
  199. echo '</div>';
  200. }
  201. }
  202. }
  203. if (!function_exists('ever_single_share')) {
  204. function ever_single_share(){
  205. if(ever_option('single_share', true)){
  206. $post_image = ever_image('full', true);
  207. echo '<div class="total-shares"><em>'.ever_share_count().'</em><div class="caption">'. esc_html__('Shares', 'ever') .'</div></div>';
  208. echo '<div class="entry-share" data-ajaxurl="'.esc_url(home_url('/')).'" data-id="'.esc_attr(get_the_id()).'">';
  209. echo '<a class="facebook" href="' . esc_url(get_permalink()) . '" title="Share this"><i class="ion-social-facebook"></i><span>'. esc_html__('Share on Facebook', 'ever') .'</span></a>';
  210. echo '<a class="twitter" href="' . esc_url(get_permalink()) . '" title="Tweet" data-title="' . esc_attr(get_the_title()) . '"><i class="ion-social-twitter"></i><span>'. esc_html__('Share on Twitter', 'ever') .'</span></a>';
  211. echo '<div class="ext-share">';
  212. echo '<a class="google" href="' . esc_url(get_permalink()) . '" title="Share"><i class="ion-social-googleplus"></i></a>';
  213. echo '<a class="linkedin" href="' . esc_url(get_permalink()) . '" title="Share" data-title="' . esc_attr(get_the_title()) . '"><i class="ion-social-linkedin"></i></a>';
  214. echo '<a class="pinterest" href="' . esc_url(get_permalink()) . '" title="Pin It" data-title="' . esc_attr(get_the_title()) . '" data-image="' . esc_attr($post_image['url']) . '"><i class="ion-social-pinterest"></i></a>';
  215. echo '</div>';
  216. echo '<div class="share-toggle header"><i class="ion-plus-round"></i><i class="ion-minus-round"></i></div>';
  217. echo '</div>';
  218. }
  219. }
  220. }
  221.  
  222. if (!function_exists('ever_author')) {
  223. function ever_author(){
  224. $description = get_the_author_meta('description');
  225. if ($description != ''){ ?>
  226. <div class="tw-author-box">
  227. <div class="author-box">
  228. <?php
  229. $tw_author_email = get_the_author_meta('email');
  230. echo get_avatar($tw_author_email, $size = '100');
  231. ?>
  232. <h3><?php
  233. if (is_author()){
  234. the_author();
  235. }else{
  236. the_author_posts_link();
  237. } ?>
  238. </h3>
  239. <?php
  240. echo '<p>';
  241. echo esc_html($description);
  242. echo '</p>';
  243. $socials = get_the_author_meta('user_social');
  244. if(!empty($socials)){
  245. echo '<div class="author-entry-share">';
  246. $social_links=explode("\n",$socials);
  247. foreach($social_links as $social_link){
  248. $icon = ever_social_icon(esc_url($social_link));
  249. echo '<a href="'.esc_url($social_link).'"><i class="'.esc_attr($icon).'"></i></a>';
  250. }
  251. echo '</div>';
  252. } ?>
  253. </div>
  254. </div><?php
  255. }
  256. }
  257. }
  258.  
  259. if (!function_exists('ever_comment_form')) {
  260. function ever_comment_form($fields) {
  261. global $id, $post_id;
  262. if (null === $post_id)
  263. $post_id = $id;
  264. else
  265. $id = $post_id;
  266.  
  267. $commenter = wp_get_current_commenter();
  268. $req = get_option('require_name_email');
  269. $aria_req = ( $req ? " aria-required='true'" : '' );
  270.  
  271. $fields = array(
  272. 'author' => '<p class="comment-form-author">' .
  273. '<input id="author" name="author" placeholder="' . esc_html__('Name *', 'ever') . '" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30"' . $aria_req . ' />' . '</p>',
  274. 'email' => '<p class="comment-form-email">' .
  275. '<input id="email" name="email" placeholder="' . esc_html__('Email *', 'ever') . '" type="text" value="' . esc_attr($commenter['comment_author_email']) . '" size="30"' . $aria_req . ' />' . '</p>',
  276. 'url' => '<p class="comment-form-url">' .
  277. '<input id="url" name="url" placeholder="' . esc_html__('Website', 'ever') . '" type="text" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" />' . '</p><div class="clearfix"></div>',
  278. );
  279. return $fields;
  280. }
  281. add_filter('comment_form_default_fields', 'ever_comment_form');
  282. }
  283.  
  284. if (!function_exists('ever_comment')) {
  285. function ever_comment($comment, $args, $depth){
  286. $GLOBALS['comment'] = $comment;?>
  287. <div <?php comment_class();?> id="comment-<?php comment_ID(); ?>">
  288. <div class="comment-author">
  289. <?php echo get_avatar($comment, $size = '60'); ?>
  290. </div>
  291. <div class="comment-text">
  292. <h3 class="author"><?php echo get_comment_author_link(); ?></h3>
  293. <span class="tw-meta"><?php echo get_comment_date('F j, Y'); ?></span>
  294. <?php comment_text() ?>
  295. <h6 class="reply"><?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></h6>
  296. </div><?php
  297. }
  298. }
  299.  
  300. if (!function_exists('ever_comment_count')) {
  301. function ever_comment_count() {
  302. if (comments_open()) {
  303. $comment_count = get_comments_number('0', '1', '%');
  304. if ($comment_count == 0) {
  305. $comment_trans = esc_html__('no comment', 'ever');
  306. } elseif ($comment_count == 1) {
  307. $comment_trans = esc_html__('1 comment', 'ever');
  308. } else {
  309. $comment_trans = $comment_count . ' ' . esc_html__('comments', 'ever');
  310. }
  311. return "<span class='comment-count'><a href='" . esc_url(get_comments_link()) . "' title='" . esc_attr($comment_trans) . "'>" . esc_html($comment_trans) . "</a></span>";
  312. }
  313. }
  314. }
  315. function ever_cats($sep = ', '){
  316. $cats = '';
  317. foreach((get_the_category()) as $category) {
  318. $options = get_option("taxonomy_".$category->cat_ID);
  319. if (!isset($options['featured']) || !$options['featured']){
  320. $cats .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( 'View all posts in %s', 'ever' ), $category->name ) . '" ' . '>' . $category->name.'</a><span>'.$sep.'</span>';
  321. }
  322. }
  323. if(!$cats && is_search()){
  324. $cats = '<a href="' . get_permalink() . '">' . esc_html__('Page', 'ever') . '</a>';
  325. }
  326. return $cats;
  327. }
  328. if (!function_exists('hosugar_categories_postcount')){
  329. function hosugar_categories_postcount($variable) {
  330. $pos = strpos($variable, '<option');
  331. if (!$pos) {
  332. $variable = str_replace('(', '<span class="post-count">(', $variable);
  333. $variable = str_replace(')', ')</span>', $variable);
  334. }
  335. return $variable;
  336. }
  337. }
  338. add_filter('wp_list_categories', 'hosugar_categories_postcount');
  339. add_filter('get_archives_link', 'hosugar_categories_postcount');
  340.  
  341. if (!function_exists('ever_post_share')) {
  342. function ever_post_share() {
  343. $output = '<div class="tw_post_sharebox clearfix">';
  344. $output .= '<span class="share-text">'.esc_html__('Share this Post', 'ever').'</span>';
  345. $post_title = get_the_title();
  346. $output .= '<div class="sharebox-icons">';
  347. $output .= '<div class="google"><a href="' . esc_url(get_permalink()) . '" title="Share this"><i class="ion-social-googleplus"></i></a></div>';
  348. $output .= '<div class="twitter-share"><a href="' . esc_url(get_permalink()) . '" title="Tweet" data-title="' . esc_attr($post_title) . '"><i class="ion-social-twitter"></i></a></div>';
  349. $output .= '<div class="facebook-share"><a href="' . esc_url(get_permalink()) . '" title="Share this"><i class="ion-social-facebook"></i></a></div>';
  350. $output .= '</div>';
  351. $output .= '</div>';
  352. echo balanceTags($output);
  353. }
  354. }
  355.  
  356. if(!function_exists('ever_origshare_count')){
  357. function ever_origshare_count($socials = array('facebook', 'twitter', 'pinterest')){
  358. $count = 0;
  359. foreach($socials as $social){
  360. if($social == 'facebook'){
  361. $url = get_permalink();
  362. $contents=false;
  363. try {
  364. $contents = wp_remote_get('http://graph.facebook.com/?id='.$url);
  365. } catch(Exception $e) {
  366. $s_count = 0;
  367. }
  368. if(is_array($contents)&&isset($contents['body'])) {
  369. $json = json_decode($contents['body']);
  370. $s_count = isset($json->share->share_count) ? $json->share->share_count : 0;
  371. } else {
  372. $s_count = 0;
  373. }
  374. } elseif($social == 'pinterest') {
  375. $contents=false;
  376. $url = get_permalink();
  377. try {
  378. $contents = wp_remote_get('http://widgets.pinterest.com/v1/urls/count.json?source=6&url='.$url);
  379. } catch(Exception $e) {
  380. $s_count = 0;
  381. }
  382. if(is_array($contents)&&isset($contents['body'])) {
  383. $contents['body']=str_replace(array('receiveCount(',')'),'',$contents['body']);
  384. $json = json_decode($contents['body']);
  385. $s_count = isset($json->count) ? $json->count : 0;
  386. } else {
  387. $s_count = 0;
  388. }
  389. } elseif($social == 'twitter'){
  390. global $post;
  391. $s_count = get_post_meta($post->ID, 'post_twitter', true);
  392. }
  393. $count += intval($s_count, 10);
  394. }
  395. return $count;
  396. }
  397. }
  398.  
  399. if (!function_exists('ever_share_count')){
  400.  
  401. function ever_share_count($socials = array('facebook', 'twitter', 'pinterest')){
  402. global $post;
  403. $count = 0;
  404. foreach($socials as $social){
  405. $s_count = get_post_meta($post->ID, 'post_' . $social, true);
  406. $count += intval($s_count, 10);
  407. }
  408. return intval($count, 10);
  409. }
  410.  
  411. }
  412. if (isset($_REQUEST['social_pid']) && isset($_REQUEST['social_name'])){
  413. $pid = intval($_REQUEST['social_pid']);
  414. update_post_meta($pid, 'post_' . $_REQUEST['social_name'], get_post_meta($pid, 'post_' . $_REQUEST['social_name'], true) + 1);
  415. die;
  416. }
  417.  
  418. function ever_social_link($social){
  419. if(!empty($social)){
  420. $icon = ever_social_icon(esc_url($social));
  421. return '<a href="'.esc_url($social).'"><i class="'.esc_attr($icon).'"></i></a>';
  422. }
  423. }
  424.  
  425. function ever_social_name($url){
  426. if(strpos($url,'twitter.com') > -1) { return 'twitter';}
  427. if(strpos($url,'linkedin.com') > -1){ return 'linkedin';}
  428. if(strpos($url,'facebook.com') > -1){ return 'facebook';}
  429. if(strpos($url,'delicious.com') > -1){ return 'delicious';}
  430. if(strpos($url,'codepen.io') > -1){ return 'codepen';}
  431. if(strpos($url,'github.com') > -1){ return 'github';}
  432. if(strpos($url,'wordpress.org') > -1 || strpos($url,'wordpress.com') > -1){ return 'wordpress';}
  433. if(strpos($url,'youtube.com') > -1){ return 'youtube';}
  434. if(strpos($url,'behance.net') > -1){ return 'behance';}
  435. if(strpos($url,'pinterest.com') > -1){ return 'pinterest';}
  436. if(strpos($url,'foursquare.com') > -1){ return 'foursquare';}
  437. if(strpos($url,'soundcloud.com') > -1){ return 'soundcloud';}
  438. if(strpos($url,'dribbble.com') > -1){ return 'dribbble';}
  439. if(strpos($url,'instagram.com') > -1){ return 'instagram';}
  440. if(strpos($url,'plus.google') > -1){ return 'googleplus';}
  441. if(strpos($url,'vine.co') > -1){ return 'vine';}
  442. if(strpos($url,'twitch.tv') > -1){ return 'twitch';}
  443. if(strpos($url,'tumblr.com') > -1){ return 'tumblr';}
  444. if(strpos($url,'trello.com') > -1){ return 'trello';}
  445. if(strpos($url,'spotify.com') > -1){ return 'spotify';}
  446.  
  447. return 'newsfeed';
  448. }
  449. function ever_social_icon($url){
  450. if(strpos($url,'twitter.com') > -1) { return 'ion-social-twitter';}
  451. if(strpos($url,'linkedin.com') > -1){ return 'ion-social-linkedin';}
  452. if(strpos($url,'facebook.com') > -1){ return 'ion-social-facebook';}
  453. if(strpos($url,'delicious.com') > -1) { return 'fa-delicious';}
  454. if(strpos($url,'codepen.io') > -1){ return 'ion-social-codepen';}
  455. if(strpos($url,'github.com') > -1){ return 'ion-social-github';}
  456. if(strpos($url,'wordpress.org') > -1 || strpos($url,'wordpress.com') > -1){ return 'ion-social-wordpress';}
  457. if(strpos($url,'youtube.com') > -1){ return 'ion-social-youtube';}
  458. if(strpos($url,'behance.net') > -1) { return 'fa-behance';}
  459. if(strpos($url,'pinterest.com') > -1){ return 'ion-social-pinterest';}
  460. if(strpos($url,'foursquare.com') > -1){ return 'ion-social-foursquare';}
  461. if(strpos($url,'soundcloud.com') > -1) { return 'fa-soundcloud';}
  462. if(strpos($url,'dribbble.com') > -1){ return 'ion-social-dribbble';}
  463. if(strpos($url,'instagram.com') > -1){ return 'ion-social-instagram';}
  464. if(strpos($url,'plus.google') > -1){ return 'ion-social-googleplus';}
  465. if(strpos($url,'vine.co') > -1) { return 'fa-vine';}
  466. if(strpos($url,'twitch.tv') > -1){ return 'ion-social-twitch';}
  467. if(strpos($url,'tumblr.com') > -1){ return 'ion-social-tumblr';}
  468. if(strpos($url,'apple.com') > -1){ return 'ion-social-apple';}
  469. if(strpos($url,'google.com') > -1){ return 'ion-social-android';}
  470. if(strpos($url,'microsoft.com') > -1){ return 'ion-social-windows';}
  471. if(strpos($url,'spotify.com') > -1) { return 'fa-spotify';}
  472. if(strpos($url,'snapchat.com') > -1) { return 'ion-social-snapchat';}
  473.  
  474. return 'ion-social-rss';
  475. }
  476. function ever_social_name_from_url($social_link,$option){
  477. return trim(str_replace(array_merge(array('https:','http:','www.','/'),$option), '',$social_link));
  478. }
  479. function ever_social_icons(){
  480. $socials = ever_option("socials");
  481. if(!empty($socials)){
  482. $output = '<div class="social-icons">';
  483. foreach($socials as $social){ $output .= ever_social_link(esc_url($social)); }
  484. $output .= '</div>';
  485. return $output;
  486. }
  487. }
  488.  
  489. function ever_footer_socials($sub = false){
  490. $socials = ever_option("socials");
  491. if(!empty($socials)){
  492. $output = '<div class="entry-share clearfix">';
  493. if($sub){
  494. foreach($socials as $social){
  495. if(!empty($social['href']) && !empty($social['name'])){
  496. $icon = ever_social_icon(esc_url($social['href']));
  497. $text = !empty($social['subtext']) ? ('</span><span>'.esc_attr($social['subtext'])) : '';
  498. $output .= '<div class="social-item"><a class="tw-meta" href="'.esc_url($social['href']).'"><i class="'.esc_attr($icon).'"></i><span>'.esc_attr($social['name']).$text.'</span></a></div>';
  499. }
  500. }
  501. } else {
  502. foreach($socials as $social){
  503. if(!empty($social['href']) && !empty($social['name'])){
  504. $icon = ever_social_icon(esc_url($social['href']));
  505. $output .= '<div class="social-item"><a class="tw-meta '.str_replace('ion-', '', esc_attr($icon)).'" href="'.esc_url($social['href']).'"><i class="'.esc_attr($icon).'"></i><span>'.esc_attr($social['name']).'</span></a></div>';
  506. }
  507. }
  508. }
  509.  
  510. $output .= '</div>';
  511. return $output;
  512. }
  513. }
  514.  
  515. function ever_related_posts() {
  516. global $post;
  517.  
  518. $categories = get_the_category($post->ID);
  519.  
  520. if ($categories) {
  521. $category_ids = array();
  522.  
  523. foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
  524.  
  525. $args = array(
  526. 'category__in' => $category_ids,
  527. 'post__not_in' => array($post->ID),
  528. 'posts_per_page' => 3, // Number of related posts that will be shown.
  529. 'ignore_sticky_posts' => 1,
  530. 'orderby' => 'rand'
  531. );
  532. $atts['img_size'] = 'recent_post';
  533. $my_query = new wp_query( $args );
  534. if( $my_query->have_posts() ) { ?>
  535. <div class="related-posts">
  536. <h4><?php esc_html_e('Related posts', 'ever'); ?></h4>
  537. <div class="row">
  538. <?php while( $my_query->have_posts() ) {
  539. $my_query->the_post();?>
  540. <div class="col-md-4">
  541. <div class="related-item">
  542. <h3><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h3>
  543. <span class="entry-date"><?php the_time( get_option('date_format') ); ?></span>
  544. <?php
  545. if(!($thumb = ever_standard_media($post, $atts))){
  546. $pformat = get_post_format() == "" ? "standard" : get_post_format();
  547. $thumb = '<div class="entry-media"><div class="format-icon '.esc_attr($pformat).'"></div></div>';
  548. }
  549. echo balanceTags($thumb);
  550. ?>
  551. </div>
  552. </div>
  553. <?php
  554. }
  555. echo '</div>';
  556. echo '</div>';
  557. }
  558. wp_reset_postdata();
  559. }
  560. }
  561.  
  562. function ever_seen_add(){
  563. global $post;
  564. $seen = get_post_meta($post->ID,'post_seen',true);
  565. $seen = intval($seen)+1;
  566. update_post_meta($post->ID,'post_seen',$seen);
  567. }
  568. function ever_seen_count(){
  569. global $post;
  570. $seen = get_post_meta($post->ID,'post_seen',true);
  571. return (empty($seen)?0:$seen);
  572. }
  573.  
  574. // Hex To RGB
  575. function ever_hex2rgb($hex) {
  576. $hex = str_replace("#", "", $hex);
  577.  
  578. if (strlen($hex) == 3) {
  579. $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
  580. $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
  581. $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
  582. } else {
  583. $r = hexdec(substr($hex, 0, 2));
  584. $g = hexdec(substr($hex, 2, 2));
  585. $b = hexdec(substr($hex, 4, 2));
  586. }
  587. $rgb = array($r, $g, $b);
  588. return implode(",", $rgb); // returns the rgb values separated by commas
  589. }
  590.  
  591. add_filter( 'wp_get_attachment_image_attributes', 'ever_image_attr',10,3);
  592. function ever_image_attr($attr,$attachment,$size){
  593. global $_wp_additional_image_sizes;
  594. if (!empty($attachment->post_mime_type) && $attachment->post_mime_type === 'image/gif' && isset($attachment->guid)){
  595. $width=$height=0;
  596. if(is_array($size)){
  597. list($width,$height)=$size;
  598. }elseif(is_string($size)&&isset($_wp_additional_image_sizes[$size])){
  599. $width=$_wp_additional_image_sizes[$size]['width'];
  600. $height=$_wp_additional_image_sizes[$size]['height'];
  601. }else{
  602. $width =get_option($size.'_size_w');
  603. $height=get_option($size.'_size_h');
  604. }
  605. $attr['data-animated_src'] = $attachment->guid;
  606. $attr['data-width'] = $width;
  607. $attr['data-height'] = $height;
  608. $attr['onload'] = 'loadGifImage(this)';
  609. $attr['class'].=' ever-gif';
  610. if($attr['src']===$attachment->guid){
  611. $img=wp_get_attachment_image_src($attachment->ID,'thumb');
  612. if(isset($img[0])){
  613. $attr['src']=$img[0];
  614. }
  615. }
  616. }
  617. return $attr;
  618. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement