blocksy_get_trending_posts_value([ 'paged' => $page ]) ]); } function blocksy_get_trending_posts_value($args = []) { $args = wp_parse_args( $args, [ 'paged' => 1 ] ); $query = new WP_Query( [ 'post_type' => 'post', 'order' => 'DESC', 'posts_per_page' => 4, 'orderby' => 'comment_count', 'paged' => $args['paged'] ] ); if (! $query->have_posts()) { return [ 'posts' => [], 'is_last_page' => false ]; } $result = []; while ($query->have_posts()) { $query->the_post(); $result[] = [ 'id' => get_the_ID(), 'attachment_id' => get_post_thumbnail_id(), 'title' => get_the_title(), 'url' => get_permalink(), 'image' => blocksy_image([ 'attachment_id' => get_post_thumbnail_id(), 'size' => 'thumbnail', 'ratio' => '1/1', 'tag_name' => 'div', ]) ]; } $is_last = intval($query->max_num_pages) === intval($args['paged']); wp_reset_postdata(); return [ 'posts' => $result, 'is_last_page' => $is_last ]; } function blocksy_get_trending_block_cache() { if (! is_customize_preview()) return; blocksy_add_customizer_preview_cache( blocksy_html_tag( 'div', ['data-id' => 'blocksy-trending-block'], blocksy_get_trending_block(true) ) ); } function blocksy_get_trending_block($forced = false) { if (! $forced) { blocksy_get_trending_block_cache(); } if (get_theme_mod('has_trending_block', 'no') !== 'yes') { if (! $forced) { return ''; } } $result = blocksy_get_trending_posts_value(); if (empty($result)) { return ''; } ob_start(); $data_page = 'data-page="1"'; if ($result['is_last_page']) { $data_page = ''; } $class = 'ct-trending-block'; $class .= ' ' . blocksy_visibility_classes( get_theme_mod('trending_block_visibility', [ 'desktop' => true, 'tablet' => true, 'mobile' => false, ]) ); ?>
>
$post['url'] ], $post['image'] . blocksy_html_tag( 'h3', [ 'class' => 'ct-item-title', ], $post['title'] ) ); } ?>