File: /mnt/data/dreamstour-wp/wp-content/plugins/dreams-tour/templates/author-tours.php
<?php
/**
* Template Name: Author Tours Template
*/
get_header();
$paged = isset($_GET['paged']) ? max(1, (int) $_GET['paged']) : 1;
$author_id = 0;
if (isset($_GET['author_id'])) {
$author_id = absint($_GET['author_id']);
} elseif (is_user_logged_in()) {
$author_id = get_current_user_id();
}
$args = array(
'post_type' => 'tour',
'posts_per_page' => 9,
'paged' => $paged,
'post_status' => 'publish',
);
if ($author_id > 0) {
$args['author'] = $author_id;
}
$tours_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
if ($author_id) {
$u = get_user_by('id', $author_id);
if ($u) {
$display_name = ucfirst($u->display_name);
echo esc_html(sprintf(__('Tours by %s', 'dreamstour'), $display_name));
} else {
echo esc_html(__('Tours', 'dreamstour'));
}
} else {
esc_html_e('All Tours', 'dreamstour');
}
?>
(<?php echo esc_html($tours_query->found_posts); ?> <?php esc_html_e('Tours Found', 'dreamstour'); ?>)
</h3>
<div class="row justify-content-space-between" id="tour-results">
<?php if ($tours_query->have_posts()) : ?>
<?php while ($tours_query->have_posts()) : $tours_query->the_post(); ?>
<?php
$tour_price = get_post_meta(get_the_ID(), 'tour_price', true);
$tour_offer_price = get_post_meta(get_the_ID(), 'tour_offer_price', true);
$tour_duration = get_post_meta(get_the_ID(), 'tour_duration', true);
$tour_guests = get_post_meta(get_the_ID(), 'tour_people_limit', true);
$comments = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve',
'orderby' => 'comment_date',
'order' => 'DESC'
));
$tour_id = get_the_ID();
$tour_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++;
}
}
}
$tour_rating = $rated_count > 0 ? number_format($sum_ratings / $rated_count, 1) : '0.0';
$tour_destination = get_post_meta(get_the_ID(), 'tour_destination', true);
$tour_types = get_the_terms(get_the_ID(), 'tour_category');
$gallery = get_post_meta(get_the_ID(), 'tour_gallery', true);
$author_id_post = get_the_author_meta('ID');
$author_avatar = get_avatar_url($author_id_post, array('size' => 96));
// Build Author Tours page link using author_id query param
$current_page_link = get_permalink(get_queried_object_id());
$author_link = add_query_arg(array(
'author_id' => $author_id_post,
'paged' => 1,
), $current_page_link);
$tour_image = '';
if (!empty($gallery) && is_array($gallery)) {
$tour_image = wp_get_attachment_url($gallery[0]);
}
if (!$tour_image && has_post_thumbnail()) {
$tour_image = get_the_post_thumbnail_url(get_the_ID(), 'large');
}
if (!$tour_image) {
if (function_exists('wc_placeholder_img_src')) {
$tour_image = wc_placeholder_img_src();
} else {
$tour_image = plugins_url('assets/img/tours-07.jpg', dirname(__FILE__));
}
}
?>
<div class="col-xxl-4 col-md-6 d-flex">
<div class="place-item mb-4 flex-fill">
<div class="place-img">
<div class="img-slider image-slide owl-carousel nav-center">
<?php
$gallery = get_post_meta(get_the_ID(), 'tour_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) {
echo '<div class="slide-images">'
. '<a href="' . esc_url(get_permalink()) . '">'
. '<img src="' . esc_url($img_url) . '" class="img-fluid" alt="' . esc_attr(get_the_title()) . '">'
. '</a>'
. '</div>';
}
}
} else {
if ($tour_image) {
echo '<div class="slide-images">'
. '<a href="' . esc_url(get_permalink()) . '">'
. '<img src="' . esc_url($tour_image) . '" class="img-fluid" alt="' . esc_attr(get_the_title()) . '">'
. '</a>'
. '</div>';
}
}
?>
</div>
<div class="fav-item">
<?php $wishlist_active = is_user_logged_in() ? (function_exists('dreamstour_is_in_wishlist') ? dreamstour_is_in_wishlist(get_current_user_id(), $tour_id) : false) : false; ?>
<a href="javascript:void(0);" id="dt-wishlist-btn" data-tour-id="<?php echo esc_attr((int) $tour_id); ?>" data-tour-title="<?php echo esc_attr(get_the_title($tour_id)); ?>" class="fav-icon <?php echo sanitize_html_class($wishlist_active ? 'selected' : ''); ?>">
<i class="isax isax-heart5"></i>
</a>
<span class="badge bg-info d-inline-flex align-items-center"><i class="isax isax-ranking me-1"></i><?php esc_html_e('Trending','dreamstour'); ?></span>
</div>
</div>
<div class="place-content">
<div class="d-flex align-items-center justify-content-between mb-1">
<div class="d-flex flex-wrap align-items-center">
<span class="me-1"><i class="ti ti-receipt text-primary"></i></span>
<p class="fs-14 text-gray-9">
<?php
if ($tour_types && !is_wp_error($tour_types)) {
echo esc_html($tour_types[0]->name);
} else {
esc_html_e('Tour','dreamstour');
}
?>
</p>
</div>
<span class="d-inline-block border vertical-splits"><span class="bglight text-light d-flex align-items-center justify-content-center"></span></span>
<div class="d-flex align-items-center flex-wrap">
<span class="badge badge-warning badge-xs text-gray-9 fs-13 fw-medium me-1"><?php echo esc_html($tour_rating ? $tour_rating : '0.0'); ?></span>
<p class="fs-14">(<?php echo esc_html($tour_reviews ? $tour_reviews : '0'); ?> <?php echo esc_html__('Reviews', 'dreamstour'); ?>)</p>
</div>
</div>
<h5 class="mb-1 text-truncate text-capitalize"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<p class="d-flex align-items-center mb-3 text-capitalize">
<i class="isax isax-location5 me-2"></i>
<?php
if ($tour_destination) {
echo esc_html($tour_destination);
} else {
echo esc_html(wp_strip_all_tags(get_the_excerpt()));
}
?>
</p>
<div class="mb-3">
<h6 class="d-flex align-items-center text-gray-6 fs-14 fw-normal">
<?php esc_html_e('Starts From','dreamstour'); ?>
<?php if ($tour_offer_price) : ?>
<span class="ms-1 fs-18 fw-semibold text-primary"><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($tour_offer_price); ?></span>
<span class="ms-1 fs-18 fw-semibold text-gray-3 text-decoration-line-through"><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($tour_price); ?></span>
<?php else : ?>
<span class="ms-1 fs-18 fw-semibold text-primary"><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($tour_price ? $tour_price : '0'); ?></span>
<?php endif; ?>
</h6>
</div>
<div class="d-flex align-items-center justify-content-between border-top pt-3">
<div class="d-flex flex-wrap align-items-center me-2">
<span class="me-1"><i class="isax isax-calendar-tick text-gray-6"></i></span>
<p class="fs-14 text-gray-9">
<?php
$days_terms = get_the_terms(get_the_ID(), 'tour_duration_days');
$nights_terms = get_the_terms(get_the_ID(), 'tour_duration_nights');
$days = ($days_terms && !is_wp_error($days_terms)) ? $days_terms[0]->name : '';
$nights = ($nights_terms && !is_wp_error($nights_terms)) ? $nights_terms[0]->name : '';
if ($days || $nights) {
echo esc_html(trim($days . ($days && $nights ? ', ' : '') . $nights));
} else {
esc_html_e('N/A','dreamstour');
}
?>
</p>
</div>
<span class="d-inline-block border vertical-splits"><span class="bglight text-light d-flex align-items-center justify-content-center"></span></span>
<div class="ms-2 d-flex align-items-center">
<p class="fs-14 text-gray-9 mb-0 text-truncate d-flex align-items-center">
<i class="isax isax-profile-2user me-1"></i>
<?php echo esc_html($tour_guests ? $tour_guests : '0'); ?> <?php echo esc_html__('Guests', 'dreamstour'); ?>
</p>
<a href="<?php echo esc_url($author_link); ?>" class="avatar avatar-sm ms-3">
<img src="<?php echo esc_url($author_avatar); ?>" class="rounded-circle" alt="<?php the_author(); ?>">
</a>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="col-12">
<div class="alert alert-info"><?php esc_html_e('No tours found matching your criteria.','dreamstour'); ?></div>
</div>
<?php endif; wp_reset_postdata(); ?>
</div>
<nav class="pagination-nav" id="tour-pagination">
<?php
$current_page = max(1, (int) $paged);
$total_pages = (int) $tours_query->max_num_pages;
if ($total_pages > 1) {
echo '<ul class="pagination justify-content-center">';
// Previous button
if ($current_page > 1) {
$prev_url = add_query_arg(array(
'author_id' => $author_id,
'paged' => $current_page - 1,
), get_permalink());
echo '<li class="page-item">';
echo '<a class="page-link" href="' . esc_url($prev_url) . '" aria-label="Previous">';
echo '<span aria-hidden="true"><i class="fa-solid fa-chevron-left"></i></span>';
echo '</a>';
echo '</li>';
} else {
echo '<li class="page-item disabled">';
echo '<a class="page-link" href="javascript:void(0);" aria-label="Previous">';
echo '<span aria-hidden="true"><i class="fa-solid fa-chevron-left"></i></span>';
echo '</a>';
echo '</li>';
}
// Page numbers
for ($i = 1; $i <= $total_pages; $i++) {
$is_active = ($i === (int) $current_page);
$page_url = add_query_arg(array(
'author_id' => $author_id,
'paged' => $i,
), get_permalink());
echo '<li class="page-item' . ($is_active ? ' active' : '') . '">';
echo '<a class="page-link" href="' . esc_url($page_url) . '">' . (int) $i . '</a>';
echo '</li>';
}
// Next button
if ($current_page < $total_pages) {
$next_url = add_query_arg(array(
'author_id' => $author_id,
'paged' => $current_page + 1,
), get_permalink());
echo '<li class="page-item">';
echo '<a class="page-link" href="' . esc_url($next_url) . '" aria-label="Next">';
echo '<span aria-hidden="true"><i class="fa-solid fa-chevron-right"></i></span>';
echo '</a>';
echo '</li>';
} else {
echo '<li class="page-item disabled">';
echo '<a class="page-link" href="javascript:void(0);" aria-label="Next">';
echo '<span aria-hidden="true"><i class="fa-solid fa-chevron-right"></i></span>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
?>
</nav>
<?php wp_reset_postdata(); ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>