' . esc_html__('Activity service is not available.', 'yatra') . '

'; yatra_get_footer(); return; } $activity_service = new \Yatra\Services\ActivityService(); // Fetch published activities with stats (including trips_count, avg_rating, starting_price) $activities = $activity_service->getPublishedWithStats(); // Apply simple server-side sorting and pagination for UX. $sort = isset($_GET['yatra_sort']) ? sanitize_text_field(wp_unslash($_GET['yatra_sort'])) : 'rating_desc'; if (!empty($activities) && is_array($activities)) { yatra_sort_archive_listing_stats_rows($activities, $sort); } $per_page = yatra_get_posts_per_page(); $current_page = yatra_get_archive_listing_paged(); $total_items = is_array($activities) ? count($activities) : 0; $total_pages = $total_items > 0 ? (int) ceil($total_items / $per_page) : 1; $current_page = min($current_page, $total_pages); $offset = ($current_page - 1) * $per_page; $paged_activities = $total_items > 0 ? array_slice($activities, $offset, $per_page) : []; $yatra_browse_start = $total_items > 0 ? $offset + 1 : 0; $yatra_browse_end = $total_items > 0 ? min($offset + $per_page, $total_items) : 0; $yatra_browse_line = function_exists('yatra_archive_browse_results_line') ? yatra_archive_browse_results_line( $yatra_browse_start, $yatra_browse_end, $total_items, $current_page, $total_pages, __('activities', 'yatra') ) : ''; $GLOBALS['yatra_archive_browse_pagination'] = [ 'current_page' => (int) $current_page, 'total_pages' => (int) $total_pages, ]; yatra_get_header(); ?>

name) ? $activity->name : ''; $description = isset($activity->description) ? $activity->description : ''; // Resolve image/icon from the stored icon field when possible. $image_url = ''; $icon_class = ''; if (!empty($activity->icon)) { $icon = maybe_unserialize($activity->icon); if (is_array($icon)) { // Handle both newer format ['type' => 'icon', 'value' => 'footprint'] // and older format [0 => 'icon', 1 => 'footprint'] $type = $icon['type'] ?? $icon[0] ?? ''; $value = $icon['value'] ?? $icon[1] ?? ''; if ($type === 'image' && !empty($value)) { if (is_numeric($value)) { $maybe_url = wp_get_attachment_image_url((int) $value, 'large'); if (!empty($maybe_url)) { $image_url = $maybe_url; } } elseif (is_string($value) && filter_var($value, FILTER_VALIDATE_URL)) { $image_url = $value; } } elseif ($type === 'icon' && !empty($value) && is_string($value)) { // Store icon name so yatra_svg_icon() can render the same SVG // icon as used in the React admin (e.g. 'camera'). $icon_class = $value; } elseif (!empty($icon['url']) && filter_var($icon['url'], FILTER_VALIDATE_URL)) { // Legacy format: ['url' => 'https://...'] $image_url = $icon['url']; } elseif (!empty($icon['id'])) { // Legacy format: ['id' => attachment_id] $maybe_url = wp_get_attachment_image_url((int) $icon['id'], 'large'); if (!empty($maybe_url)) { $image_url = $maybe_url; } } } elseif (is_numeric($icon)) { $maybe_url = wp_get_attachment_image_url((int) $icon, 'large'); if (!empty($maybe_url)) { $image_url = $maybe_url; } } elseif (is_string($icon) && filter_var($icon, FILTER_VALIDATE_URL)) { $image_url = $icon; } } // Basic stats: only use real DB fields when present; do not fake numbers. $has_avg_rating = isset($activity->avg_rating) && (float) $activity->avg_rating > 0; $avg_rating = $has_avg_rating ? (float) $activity->avg_rating : 0.0; $has_trips_count = isset($activity->trips_count) && (int) $activity->trips_count > 0; $trips_count = $has_trips_count ? (int) $activity->trips_count : 0; $starting_price_raw = isset($activity->starting_price) ? (float) $activity->starting_price : 0.0; $has_starting_price = $starting_price_raw > 0; // Use core helper to format price with correct currency symbol & settings. $starting_price = $has_starting_price ? yatra_format_price($starting_price_raw) : ''; // Build permalink $permalink = function_exists('yatra_get_activity_permalink') ? yatra_get_activity_permalink($activity->id ?? $activity) : ''; ?>

1) : ?>
= $current_page - $range && $i <= $current_page + $range)) : if ($i === $current_page) : ?> ... = $total_pages) : ?>