$args * @return list<\WP_Post> */ function aksrt_user_card_query_posts(array $args): array { $user_id = (int) ($args['user_id'] ?? 0); $limit = max(0, min(20, (int) ($args['limit'] ?? 6))); if ($user_id <= 0 || $limit <= 0) { return []; } $orderby = sanitize_key((string) ($args['orderby'] ?? 'date')); $post_type = sanitize_key((string) ($args['post_type'] ?? 'post')); if (!post_type_exists($post_type)) { $post_type = 'post'; } $query_args = [ 'post_status' => 'publish', 'post_type' => $post_type, 'author' => $user_id, 'posts_per_page' => $limit, 'ignore_sticky_posts' => true, 'no_found_rows' => true, ]; $exclude = (int) ($args['exclude'] ?? 0); if ($exclude <= 0) { $exclude = (int) get_the_ID(); } if ($exclude > 0) { $query_args['post__not_in'] = [$exclude]; } switch ($orderby) { case 'views': case 'view': $query_args['meta_key'] = 'aksrt_post_views'; $query_args['orderby'] = 'meta_value_num'; $query_args['order'] = 'DESC'; break; case 'comment_count': case 'comments': $query_args['orderby'] = 'comment_count'; $query_args['order'] = 'DESC'; break; case 'modified': $query_args['orderby'] = 'modified'; $query_args['order'] = 'DESC'; break; case 'rand': case 'random': $query_args['orderby'] = 'rand'; break; default: $query_args['orderby'] = 'date'; $query_args['order'] = 'DESC'; } $q = new WP_Query($query_args); $posts = $q->posts; wp_reset_postdata(); return is_array($posts) ? array_values(array_filter($posts, static fn($p) => $p instanceof WP_Post)) : []; } endif; if (!function_exists('aksrt_render_user_card_posts')) : /** * Render more-posts strip (card swiper-scroll or mini list). * * @param array $args */ function aksrt_render_user_card_posts(array $args): string { $style = sanitize_key((string) ($args['post_style'] ?? $args['style'] ?? 'mini')); if (!in_array($style, ['card', 'mini'], true)) { $style = 'mini'; } $posts = aksrt_user_card_query_posts($args); $show_empty = !empty($args['show_empty']); if (!$posts) { if (!$show_empty) { return ''; } return '
' . esc_html__('暂无更多文章', 'aksrt') . '
'; } ob_start(); echo '
'; if ($style === 'card') { echo ''; } else { echo ''; } echo '
'; return (string) ob_get_clean(); } endif;