File: /mnt/data/dreamssalon-wp/wp-content/themes/dreamsalon/taxonomy-service_branch.php
<?php
/**
* Template for Service Branch Archive
* File: taxonomy-service_category.php
*/
get_header();
// Current category object
$term = get_queried_object();
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// Custom query for Services in this category
$args = array(
'post_type' => 'service',
'posts_per_page' => 9,
'paged' => $paged,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'service_branch',
'field' => 'slug',
'terms' => $term->slug,
),
),
);
$services_query = new WP_Query( $args );
?>
<div class="content">
<div class="container">
<div class="row">
<div class="col-xl-12 col-lg-12 theiaStickySidebar">
<h3 class="mb-4">
<?php echo esc_html( $term->name ); ?>
(<?php echo esc_html( $services_query->found_posts ); ?> <?php esc_html_e( 'Services Found', 'dreamsalon' ); ?>)
</h3>
<div class="row listing-item-row row-gap-4 mb-0 justify-content-start" id="service-results">
<?php if ($services_query->have_posts()) : ?>
<?php while ($services_query->have_posts()) : $services_query->the_post(); ?>
<?php
$service_price = get_post_meta(get_the_ID(), 'service_price', true);
$service_offer_price = get_post_meta(get_the_ID(), 'service_offer_price', true);
$service_duration = get_post_meta(get_the_ID(), 'service_duration', true);
$service_guests = get_post_meta(get_the_ID(), 'service_people_limit', true);
// Compute rating and review count from approved comments (like single-service)
$comments = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve',
'orderby' => 'comment_date',
'order' => 'DESC'
));
$service_id = get_the_ID();
$service_reviews = is_array($comments) ? count($comments) : 0;
$sum_ratings = 0;
$rated_count = 0;
if ($comments) {
foreach ($comments as $c) {
$r = get_comment_meta($c->comment_ID, 'rating', true);
if ($r) {
$sum_ratings += intval($r);
$rated_count++;
}
}
}
$service_rating = $rated_count > 0 ? number_format($sum_ratings / $rated_count, 1) : '0.0';
$service_destination = get_post_meta(get_the_ID(), 'service_address', true);
$service_types = get_the_terms(get_the_ID(), 'service_category');
$gallery = get_post_meta(get_the_ID(), 'service_gallery', true);
$author_id = get_the_author_meta('ID');
$author_avatar = get_avatar_url($author_id, array('size' => 96));
// Build Author Service page link using author_id query param
$author_services_page = function_exists('dreamsalon_fl_framework_getoptions') ? dreamsalon_fl_framework_getoptions('author_services_page') : 0;
$author_services_page_url = $author_services_page ? get_permalink($author_services_page) : '';
$author_link = $author_services_page_url ? add_query_arg(array(
'author_id' => (int) $author_id,
), $author_services_page_url) : 'javascript:void(0);';
$branch_terms = wp_get_post_terms(get_the_ID(), 'service_branch');
$location = '';
if (!is_wp_error($branch_terms) && !empty($branch_terms)){
$first_term = $branch_terms[0];
$location = $first_term->name;
}
// Get first image from gallery or featured image
$service_image = '';
if (!empty($gallery) && is_array($gallery)) {
$service_image = wp_get_attachment_url($gallery[0]);
}
if (!$service_image && has_post_thumbnail()) {
$service_image = get_the_post_thumbnail_url(get_the_ID(), 'large');
}
if (!$service_image) {
$service_image = plugin_dir_url(__FILE__) . 'assets/img/salons-07.jpg';
}
?>
<!-- Service Card (Listing Style) -->
<div class="col-xl-4 col-lg-6 col-md-6 d-flex">
<div class="listing-item flex-fill mb-0">
<div class="listing-item-img mb-0 rounded-0 shiny position-relative overflow-hidden">
<div class="listing-slider mb-0">
<?php
// Fetch gallery images (array of image IDs or URLs)
$gallery = get_post_meta(get_the_ID(), 'service_gallery', true);
if ($gallery && is_array($gallery)) {
foreach ($gallery as $img_id) {
$img_url = wp_get_attachment_image_url($img_id, 'large');
if ($img_url) {
?>
<div class="listing-slider-item">
<a href="<?php the_permalink(); ?>">
<img class="img-fluid" src="<?php echo esc_url($img_url); ?>" alt="<?php the_title_attribute(); ?>">
</a>
</div>
<?php
}
}
} else {
// Fallback to featured image
if (has_post_thumbnail()) {
?>
<div class="listing-slider-item">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('large', array('class' => 'img-fluid', 'alt' => get_the_title())); ?>
</a>
</div>
<?php
} else {
// Fallback to a placeholder image
$placeholder_image = function_exists('wc_placeholder_img_src') ? wc_placeholder_img_src() : '';
if ($placeholder_image) {
?>
<div class="listing-slider-item">
<a href="<?php the_permalink(); ?>">
<img class="img-fluid" src="<?php echo esc_url($placeholder_image); ?>" alt="<?php the_title_attribute(); ?>">
</a>
</div>
<?php
}
}
}
?>
</div>
<div class="listing-badge-item d-flex align-items-center justify-content-end position-absolute top-0 start-0 end-0">
<?php $wishlist_active = is_user_logged_in() ? (function_exists('dreamservice_is_in_wishlist') ? dreamservice_is_in_wishlist(get_current_user_id(), $service_id) : false) : false; ?>
<button
class="favourite <?php echo esc_attr( $wishlist_active ? 'selected' : '' ); ?>"
aria-label="Add to favourites"
id="dt-wishlist-btn"
data-service-id="<?php echo esc_attr( (int) $service_id ); ?>"
data-service-title="<?php echo esc_attr( get_the_title( $service_id ) ); ?>"
>
<i class="ti ti-heart<?php echo esc_attr( $wishlist_active ? '-filled filled' : '' ); ?>"></i>
</button>
</div>
</div>
<div class="listing-item-content">
<div class="d-flex align-items-center justify-content-between mb-3">
<div class="d-flex align-items-center justify-content-center gap-1">
<?php
$rating_value = (float) $service_rating;
for ($i = 1; $i <= 5; $i++) :
$star_class = $i <= floor($rating_value) ? 'text-warning' : 'text-light';
?>
<i class="ti ti-star-filled <?php echo esc_attr($star_class); ?>"></i>
<?php endfor; ?>
<p class="mb-0"> <span class="text-dark"><?php echo esc_html($service_rating ? $service_rating : '0.0'); ?></span> (<?php echo esc_html($service_reviews ? $service_reviews : '0'); ?> <?php esc_html_e('Reviews','dreamsalon'); ?>)</p>
</div>
</div>
<div class="d-flex align-items-center justify-content-between mb-3 pb-3 border-bottom">
<div>
<h3 class="title mb-1">
<a href="<?php the_permalink(); ?>" class="d-flex align-items-center gap-2">
<?php the_title(); ?>
</a>
</h3>
<?php if ($location): ?>
<p class="d-flex align-items-center text-capitalize"><i class="isax isax-location5 me-2"></i><?php
$__loc = $location; echo esc_html( $__loc );
?></p>
<?php endif; ?>
</div>
</div>
<div class="d-flex align-items-center justify-content-between flex-wrap gap-1">
<div>
<p class="mb-1"><?php esc_html_e('Starts From','dreamsalon'); ?></p>
<?php
$base_price_raw = is_numeric($service_price) ? (float) $service_price : 0;
$offer_price_raw = is_numeric($service_offer_price) ? (float) $service_offer_price : 0;
?>
<p class="mb-0 price">
<strong>
<?php if ($offer_price_raw > 0) : ?>
<?php
if (function_exists('wc_price')) {
echo wp_kses_post(wc_price($offer_price_raw));
} else {
$sym = function_exists('get_woocommerce_currency_symbol') ? get_woocommerce_currency_symbol() : '$';
echo esc_html($sym . number_format_i18n($offer_price_raw, 2));
}
?>
<?php else : ?>
<?php
if (function_exists('wc_price')) {
echo wp_kses_post(wc_price($base_price_raw));
} else {
$sym = function_exists('get_woocommerce_currency_symbol') ? get_woocommerce_currency_symbol() : '$';
echo esc_html($sym . number_format_i18n($base_price_raw, 2));
}
?>
<?php endif; ?>
</strong>
</p>
</div>
<div class="avatar user-avatar">
<a href="<?php echo esc_url($author_link); ?>">
<img src="<?php echo esc_url($author_avatar); ?>" alt="<?php the_author(); ?>" class="rounded-circle border">
</a>
</div>
</div>
</div>
</div>
</div>
<!-- /Service Card (Listing Style) -->
<?php endwhile; ?>
<?php else : ?>
<div class="col-12">
<div class="alert alert-info"><?php esc_html_e('No services found matching your criteria.','dreamsalon');?></div>
</div>
<?php endif;
wp_reset_postdata(); ?>
</div>
<!-- Pagination -->
<nav class="pagination-nav">
<?php
echo paginate_links(
array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $services_query->max_num_pages,
'prev_text' => '<i class="fa-solid fa-chevron-left"></i>',
'next_text' => '<i class="fa-solid fa-chevron-right"></i>',
)
);
?>
</nav>
<?php wp_reset_postdata(); ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>