public static function the_related_posts(array $args = []) { global $post; $cache_group_id = 'related_posts'; $cache = theme_cache::get($post->ID, $cache_group_id); if ($cache) { echo $cache; unset($cache); return; } $defaults = ['posts_per_page' => 8, 'orderby' => 'latest']; $query_args = ['post__not_in' => [$post->ID]]; $args = array_merge($defaults, $args); $content_args = ['classes' => ' ']; ob_start(); ?> <div class="related-posts panel"> <div class="heading"> <h3 class="title"> <i class="fa fa-heart-o"></i> <?php echo ___('Maybe you will like them'); ?> </h3> </div> <div class="body"> <?php $same_tag_args = $args; $same_tag_query = $query_args; /** * if post not tags, get related post from same category */ if (!get_the_tags()) { $same_tag_query['category__in'] = array_map(function ($term) { return $term->term_id; }, get_the_category($post->ID)); $same_tag_args['orderby'] = 'random'; } else { $same_tag_query['tag__in'] = array_map(function ($term) { return $term->term_id; }, get_the_tags()); } $query = self::get_posts_query($same_tag_args, $same_tag_query); if ($query->have_posts()) { ?> <div class="row"> <?php foreach ($query->posts as $post) { setup_postdata($post); self::archive_card_xs($content_args); } wp_reset_postdata(); ?> </div> <?php } else { ?> <div class="page-tip"><?php echo status_tip('info', ___('No data.')); ?> </div> <?php } //wp_reset_query(); ?> </div> </div> <?php $cache = ob_get_contents(); ob_end_clean(); theme_cache::set($post->ID, $cache, $cache_group_id, 3600); echo $cache; unset($cache); }
public static function frontend_display($args = [], $instance = []) { $cache_id = md5(json_encode($instance)); $cache = theme_cache::get($cache_id); if ($cache) { echo $cache; unset($cache); return; } $smallest = 11; $largest = 20; $unit = 'pt'; $number = $instance['number']; $exclude_ids = isset($instance['ids']) ? $instance['ids'] : null; $tag_links = []; $sticky_links = []; if (!empty($exclude_ids)) { foreach ($exclude_ids as $k => $v) { $sticky_name = isset($sticky_names[$k]) ? esc_html($sticky_names[$k]) : null; $sticky_links[] = '<a href="' . get_tag_link($v) . '" class="sticky-tag">' . $sticky_name . '</a>'; } } $tags = get_terms('post_tag', array('orderby' => 'count', 'number' => $number, 'order' => 'desc', 'pad_counts' => true, 'exclude' => $exclude_ids)); if (!empty($tags)) { $counts = []; $real_counts = []; // For the alt tag foreach ((array) $tags as $key => $tag) { $real_counts[$key] = $tag->count; $counts[$key] = $tag->count; } $min_count = min($counts); $spread = max($counts) - $min_count; if ($spread <= 0) { $spread = 1; } $font_spread = $largest - $smallest; if ($font_spread < 0) { $font_spread = 1; } $font_step = $font_spread / $spread; foreach ($tags as $key => $tag) { $count = $counts[$key]; ob_start(); ?> <a class="hot-tag" href="<?php echo get_tag_link($tag->term_id); ?> " style=" font-size:<?php echo str_replace(',', '.', $smallest + ($count - $min_count) * $font_step), $unit; ?> ; color:rgb(<?php echo mt_rand(50, 200); ?> ,<?php echo mt_rand(50, 200); ?> ,<?php echo mt_rand(50, 200); ?> );" ><?php echo esc_html($tag->name); ?> </a><?php $tag_links[] = html_minify(ob_get_contents()); ob_end_clean(); } } $tags = array_filter(array_merge($tag_links, $sticky_links)); if (!empty($tags)) { //shuffle($tags); $cache = implode('', $tags); } else { $cache = status_tip('info', ___('No data yet.')); } theme_cache::set($cache_id, $cache, null, 3600 * 24); echo $cache; unset($cache); }
public static function set_cache($data) { theme_cache::set(__CLASS__, $data); }
public static function set_cache($data) { theme_cache::set('content', $data, __CLASS__, 3600); }
public static function display_frontend() { $device = wp_is_mobile() ? 'mobile' : 'desktop'; $type = wp_is_mobile() ? 'scroller' : self::get_type(); $cache = (array) theme_cache::get(__CLASS__); if (isset($cache[$device])) { echo $cache[$device]; unset($cache); return; } ob_start(); $type = 'display_frontend_' . $type; self::$type(); /** ad */ if (!empty(self::display_frontend_ad('below'))) { ?> <div class="g <?php echo __CLASS__; ?> -ad-below"><?php echo self::display_frontend_ad('below'); ?> </div> <?php } $cache[$device] = html_minify(ob_get_contents()); ob_end_clean(); theme_cache::set(__CLASS__, $cache); echo $cache[$device]; unset($cache); }
public static function the_recommend_posts(array $args = []) { $cache = theme_cache::get('recommend', 'page-rank'); if (!empty($cache)) { echo $cache; return $cache; } global $post; $args = array_merge(['posts_per_page ' => 100, 'paged' => 1, 'orderby' => 'rand', 'post__in' => theme_recommended_post::get_ids(), 'ignore_sticky_posts' => false], $args); $query = new WP_Query($args); ob_start(); if ($query->have_posts()) { ?> <div class="list-group"> <?php $i = 1; foreach ($query->posts as $post) { setup_postdata($post); self::rank_img_content(['index' => $i, 'lazyload' => $i <= 5 ? false : true]); ++$i; } ?> </div> <?php wp_reset_postdata(); } else { } $cache = html_minify(ob_get_contents()); ob_end_clean(); theme_cache::set('recommend', $cache, 'page-rank', 3600); echo $cache; return $cache; }