- ';
foreach ($card['posts'] as $post_item) {
echo '
- '; echo '' . esc_html($post_item['title']) . ''; if ($show_dates && $post_item['date'] !== '') { echo '' . esc_html($post_item['date']) . ''; } echo ' '; } echo '
'widget_aksrt_category_recommend', 'description' => esc_html__('分类推荐卡片区块,可挂载到首页内容挂载区。', 'aksrt'), 'customize_selective_refresh' => true, ] ); } public static function render_html(array $instance): string { $category_ids = aksrt_home_widget_normalize_category_ids($instance['category_ids'] ?? [], 4); $posts_per_cat = max(1, min(8, (int) ($instance['posts_per_category'] ?? 5))); $columns = max(1, min(4, (int) ($instance['columns'] ?? 2))); $show_views = ! empty($instance['show_views']); $show_description = ! empty($instance['show_description']); $show_dates = ! empty($instance['show_dates']); $show_more = ! empty($instance['show_more']); if (empty($category_ids)) { $category_ids = aksrt_home_widget_fallback_category_ids(4); } $cards = self::build_cards_static($category_ids, $posts_per_cat, $show_views, $show_description); if (empty($cards)) { return function_exists('aksrt_get_widget_null') ? aksrt_get_widget_null(__('暂无推荐分类', 'aksrt')) : '
'; } $lazy = aksrt_home_widget_get_lazyload_args(); ob_start(); printf('
id="get_field_id('show_views')); ?>" name="get_field_name('show_views')); ?>" value="1">
id="get_field_id('show_description')); ?>" name="get_field_name('show_description')); ?>" value="1">
id="get_field_id('show_dates')); ?>" name="get_field_name('show_dates')); ?>" value="1">
id="get_field_id('show_more')); ?>" name="get_field_name('show_more')); ?>" value="1">
sanitize_text_field($new_instance['title'] ?? ''), 'category_ids' => aksrt_home_widget_normalize_category_ids($new_instance['category_ids'] ?? [], 4), 'posts_per_category' => max(1, min(8, absint($new_instance['posts_per_category'] ?? 5))), 'columns' => max(1, min(4, absint($new_instance['columns'] ?? 2))), 'show_views' => ! empty($new_instance['show_views']) ? 1 : 0, 'show_description' => ! empty($new_instance['show_description']) ? 1 : 0, 'show_dates' => ! empty($new_instance['show_dates']) ? 1 : 0, 'show_more' => ! empty($new_instance['show_more']) ? 1 : 0, ]; } /** * Build category recommend cards. * * @param array