コード例 #1
0
    public static function frontend_display(array $args = [], $instance)
    {
        $instance = array_merge(['title' => ___('Posts rank'), 'posts_per_page' => 6, 'date' => 'all', 'orderby' => 'latest', 'category__in' => [], 'content_type' => 'img'], $instance);
        $title = esc_html($instance['title']);
        echo $args['before_title'];
        if (count($instance['category__in']) === 1 && isset($instance['category__in'][0])) {
            ?>
			<a class="link" href="<?php 
            echo get_category_link($instance['category__in'][0]);
            ?>
" title="<?php 
            echo sprintf(___('Views more about %s'), $title);
            ?>
">
				<i class="fa fa-bar-chart"></i> 
				<?php 
            echo $title;
            ?>
			</a>
			<a href="<?php 
            echo get_category_link($instance['category__in'][0]);
            ?>
" title="<?php 
            echo sprintf(___('Views more about %s'), $title);
            ?>
" class="more"><?php 
            echo ___('More &raquo;');
            ?>
</a>
		<?php 
        } else {
            ?>
			<i class="fa fa-bar-chart"></i> <?php 
            echo $title;
            ?>
		<?php 
        }
        ?>
		
		<?php 
        echo $args['after_title'];
        global $post;
        $query = theme_functions::get_posts_query(['category__in' => (array) $instance['category__in'], 'posts_per_page' => (int) $instance['posts_per_page'], 'date' => $instance['date'], 'orderby' => $instance['orderby']]);
        if ($query->have_posts()) {
            ?>
			<ul class="list-group list-group-<?php 
            echo $instance['content_type'];
            ?>
 widget-orderby-<?php 
            echo $instance['orderby'];
            ?>
">
				<?php 
            foreach ($query->posts as $post) {
                setup_postdata($post);
                if ($instance['content_type'] === 'tx') {
                    theme_functions::widget_rank_tx_content(['meta_type' => $instance['orderby']]);
                } else {
                    theme_functions::widget_rank_img_content();
                }
            }
            wp_reset_postdata();
            ?>
			</ul>
		<?php 
        } else {
            ?>
			<div class="page-tip not-found">
				<?php 
            echo status_tip('info', ___('No data yet.'));
            ?>
			</div>
		<?php 
        }
    }