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);
    }
Пример #2
0
    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);
    }
Пример #3
0
 public static function get_cache()
 {
     return theme_cache::get(__CLASS__);
 }
Пример #4
0
    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);
    }
Пример #5
0
    public static function display_frontend()
    {
        $cache = theme_cache::get(__CLASS__);
        if (!empty($cache)) {
            echo $cache;
            unset($cache);
            return;
        }
        ob_start();
        $slugs = self::get_slugs();
        if (empty($slugs)) {
            ?>
<div class="page-tip"><?php 
            echo status_tip('info', ___('No cagtegory yet.'));
            ?>
</div><?php 
            return false;
        }
        global $post;
        ksort($slugs);
        foreach ($slugs as $k => $post_ids) {
            ?>
			<div class="panel-tags-index mod panel">
				<div class="heading">
					<h2 class="title">
						<span class="bg">
							<span class="tx"><?php 
            echo strtoupper($k);
            ?>
</span>
							<small> - <?php 
            echo ___('Initial');
            ?>
</small>
						</span>
					</h2>
				</div>
				<div class="row">
					<?php 
            $query = new WP_Query(array('nopaging' => true, 'post__in' => $post_ids, 'ignore_sticky_posts' => true));
            foreach ($query->posts as $post) {
                setup_postdata($post);
                theme_functions::archive_card_xs(['classes' => 'g-phone-1-2 g-tablet-1-3 g-desktop-1-4']);
            }
            unset($query);
            wp_reset_postdata();
            ?>
				</div>
			</div>
			<?php 
        }
        $cache = ob_get_contents();
        ob_end_clean();
        wp_cache_set(__CLASS__, $cache, null, 86400);
        /** 24 hours */
        echo $cache;
        unset($cache, $slugs);
    }
Пример #6
0
    public static function display_frontend()
    {
        set_time_limit(0);
        $cache_id = 'display-frontend';
        $cache = theme_cache::get($cache_id, __CLASS__);
        //$cache = false;
        if (!empty($cache)) {
            echo $cache;
            unset($cache);
            return;
        }
        ob_start();
        $whitelist = (array) self::get_options('whitelist');
        if (isset($whitelist['user-ids']) && !empty($whitelist['user-ids'])) {
            $whitelist = explode(',', $whitelist['user-ids']);
        } else {
            $whitelist = null;
        }
        global $post;
        $query = new WP_Query(['author__in' => $whitelist, 'ignore_sticky_posts' => true, 'nopaging' => true, 'post_type' => 'post']);
        if (!$query->have_posts()) {
            self::no_content(__('No posts found.'));
            return false;
        }
        //var_dump(count($query->posts));die;
        $pinyin_tags = self::get_tags($query->posts);
        unset($query);
        //var_dump($pinyin_tags);die;
        if (!$pinyin_tags) {
            self::no_content(__('No tags found.'));
            return false;
        }
        foreach ($pinyin_tags as $initial => $tags) {
            //var_dump($tags);die;
            ?>
			<div class="panel-tags-index mod panel">
				<div class="heading">
					<h2 class="title">
						<span class="bg">
							<span class="tx"><?php 
            echo strtoupper($initial);
            ?>
</span>
							<small> - <?php 
            echo ___('Pinyin initial');
            ?>
</small>
						</span>
					</h2>
				</div>
				<div class="row">
					<?php 
            foreach ($tags as $tag_id => $tag) {
                ?>
						<div class="g-phone-1-2 g-tablet-1-3 g-desktop-1-4">
							<a href="<?php 
                echo esc_url(get_tag_link($tag_id));
                ?>
" class="tags-title" target="_blank"><?php 
                echo $tag['name'];
                ?>
</a> 
							<small>(<?php 
                echo count($tag['post_ids']);
                ?>
)</small>
						</div>
					<?php 
            }
            ?>
				</div>
			</div>
			<?php 
        }
        unset($pinyin_tags);
        $cache = html_minify(ob_get_contents());
        ob_end_clean();
        wp_cache_set($cache_id, $cache, __CLASS__, 86400 * 7);
        /** 7days */
        echo $cache;
        unset($cache);
    }
Пример #7
0
    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;
    }