Files
homeproz/wp-content/themes/homeproz/single-agent.php
T
Hanson.xyz Dev 42a06a5435 Add agent listing page with ordering and disabled agent support
- Added agent_order (number) and agent_disabled (toggle) ACF fields
- Created archive-agent.php template for /agents/ listing page
  - Queries only active agents, ordered by agent_order then title
  - Grid layout with agent cards showing photo, name, title, bio
  - Contact action buttons (phone, email, profile)
- Added "Agents" link to footer fallback menu
- Updated single-agent.php to return 404 for disabled agents
- Updated property-agent.php to handle disabled agents:
  - Shows agent name and photo (for historical reference)
  - Replaces agent contact with office phone number
  - Removes Agent Profile button and email
  - Adds "Contact Us" button linking to contact form
- Added archive-agent.scss with responsive grid styles

Admin can now:
- Set display order for agents (lower numbers first)
- Disable agents who have left (hides from listing, 404s profile)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 19:10:38 -06:00

276 lines
16 KiB
PHP

<?php
/**
* Single Agent Template
*
* @package HomeProz
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Check if agent is disabled - return 404
if (have_posts()) {
the_post();
$agent_disabled = get_field('agent_disabled', get_the_ID());
if ($agent_disabled) {
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part('404');
exit;
}
rewind_posts();
}
get_header();
while (have_posts()) :
the_post();
$agent_id = get_the_ID();
// Get agent data
$agent_phone = get_field('agent_phone', $agent_id);
$agent_email = get_field('agent_email', $agent_id);
$agent_website = get_field('agent_website', $agent_id);
$agent_title = get_field('agent_title', $agent_id);
$agent_license = get_field('agent_license', $agent_id);
$agent_short_bio = get_field('agent_short_bio', $agent_id);
$agent_gallery = get_field('agent_gallery', $agent_id);
$agent_social_links = get_field('agent_social_links', $agent_id);
// Get featured image
$featured_image_id = get_post_thumbnail_id($agent_id);
$featured_image_url = $featured_image_id ? wp_get_attachment_image_url($featured_image_id, 'large') : '';
?>
<main id="primary" class="site-main Single_Agent">
<!-- Agent Header -->
<section class="agent-header">
<div class="container">
<div class="agent-header-layout">
<!-- Agent Photo -->
<div class="agent-photo-wrapper">
<?php if ($featured_image_url) : ?>
<img src="<?php echo esc_url($featured_image_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" class="agent-photo">
<?php else : ?>
<div class="agent-photo-placeholder">
<svg width="80" height="80" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" aria-hidden="true">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
<circle cx="12" cy="7" r="4"/>
</svg>
</div>
<?php endif; ?>
</div>
<!-- Agent Info -->
<div class="agent-info-wrapper">
<div class="agent-info-content">
<?php if ($agent_title) : ?>
<p class="agent-title-label"><?php echo esc_html($agent_title); ?></p>
<?php endif; ?>
<h1 class="agent-name"><?php the_title(); ?></h1>
<?php if ($agent_license) : ?>
<p class="agent-license">License #<?php echo esc_html($agent_license); ?></p>
<?php endif; ?>
<!-- Contact Actions -->
<div class="agent-contact-actions">
<?php if ($agent_phone) : ?>
<a href="tel:<?php echo esc_attr(preg_replace('/[^0-9]/', '', $agent_phone)); ?>" class="btn btn-primary">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>
</svg>
<?php echo esc_html($agent_phone); ?>
</a>
<?php endif; ?>
<?php if ($agent_email) : ?>
<a href="mailto:<?php echo esc_attr($agent_email); ?>" class="btn btn-secondary">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/>
<polyline points="22,6 12,13 2,6"/>
</svg>
Email Agent
</a>
<?php endif; ?>
</div>
<!-- Social Links -->
<?php if ($agent_social_links && is_array($agent_social_links)) : ?>
<div class="agent-social-links">
<?php foreach ($agent_social_links as $social) :
$platform = $social['platform'];
$url = $social['url'];
$icon = '';
switch ($platform) {
case 'facebook':
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"/></svg>';
break;
case 'instagram':
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="2" width="20" height="20" rx="5" ry="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></svg>';
break;
case 'linkedin':
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z"/><rect x="2" y="9" width="4" height="12"/><circle cx="4" cy="4" r="2"/></svg>';
break;
case 'twitter':
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>';
break;
case 'tiktok':
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-5.2 1.74 2.89 2.89 0 0 1 2.31-4.64 2.93 2.93 0 0 1 .88.13V9.4a6.84 6.84 0 0 0-1-.05A6.33 6.33 0 0 0 5 20.1a6.34 6.34 0 0 0 10.86-4.43v-7a8.16 8.16 0 0 0 4.77 1.52v-3.4a4.85 4.85 0 0 1-1-.1z"/></svg>';
break;
case 'youtube':
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg>';
break;
default:
$icon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>';
}
?>
<a href="<?php echo esc_url($url); ?>" target="_blank" rel="noopener noreferrer" class="social-link" title="<?php echo esc_attr(ucfirst($platform)); ?>">
<?php echo $icon; ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
<!-- Agent Details -->
<div class="container">
<div class="agent-content-layout">
<!-- Main Content -->
<div class="agent-main-content">
<!-- Biography -->
<?php if (get_the_content() || $agent_short_bio) : ?>
<section class="agent-section agent-bio">
<h2 class="section-title">About <?php the_title(); ?></h2>
<?php if ($agent_short_bio) : ?>
<p class="agent-short-bio"><?php echo esc_html($agent_short_bio); ?></p>
<?php endif; ?>
<div class="agent-full-bio">
<?php the_content(); ?>
</div>
</section>
<?php endif; ?>
<!-- Photo Gallery -->
<?php if ($agent_gallery && is_array($agent_gallery) && count($agent_gallery) > 0) : ?>
<section class="agent-section agent-gallery-section">
<h2 class="section-title">Photo Gallery</h2>
<div class="agent-gallery-grid">
<?php foreach ($agent_gallery as $image_id) :
$image_url = wp_get_attachment_image_url($image_id, 'medium_large');
$image_full = wp_get_attachment_image_url($image_id, 'full');
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
?>
<a href="<?php echo esc_url($image_full); ?>" class="gallery-item" target="_blank">
<img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt ?: get_the_title()); ?>">
</a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<!-- Agent's Listings -->
<?php
// Query properties assigned to this agent
$agent_properties = new WP_Query([
'post_type' => 'property',
'posts_per_page' => 6,
'meta_query' => [
[
'key' => 'listing_agent',
'value' => $agent_id,
'compare' => '=',
],
],
]);
if ($agent_properties->have_posts()) :
?>
<section class="agent-section agent-listings">
<h2 class="section-title">Current Listings</h2>
<div class="agent-listings-grid">
<?php while ($agent_properties->have_posts()) : $agent_properties->the_post();
get_template_part('template-parts/property/property-card');
endwhile; ?>
</div>
<div class="agent-listings-cta">
<a href="<?php echo esc_url(get_post_type_archive_link('property')); ?>" class="btn btn-secondary">View All Properties</a>
</div>
</section>
<?php
wp_reset_postdata();
endif;
?>
</div>
<!-- Sidebar -->
<aside class="agent-sidebar">
<!-- Contact Card -->
<div class="sidebar-widget agent-contact-card">
<h3 class="widget-title">Contact Information</h3>
<ul class="contact-list">
<?php if ($agent_phone) : ?>
<li class="contact-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>
</svg>
<div>
<span class="contact-label">Phone</span>
<a href="tel:<?php echo esc_attr(preg_replace('/[^0-9]/', '', $agent_phone)); ?>"><?php echo esc_html($agent_phone); ?></a>
</div>
</li>
<?php endif; ?>
<?php if ($agent_email) : ?>
<li class="contact-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/>
<polyline points="22,6 12,13 2,6"/>
</svg>
<div>
<span class="contact-label">Email</span>
<a href="mailto:<?php echo esc_attr($agent_email); ?>"><?php echo esc_html($agent_email); ?></a>
</div>
</li>
<?php endif; ?>
<?php if ($agent_website) : ?>
<li class="contact-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<circle cx="12" cy="12" r="10"/>
<line x1="2" y1="12" x2="22" y2="12"/>
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/>
</svg>
<div>
<span class="contact-label">Website</span>
<a href="<?php echo esc_url($agent_website); ?>" target="_blank" rel="noopener noreferrer">Visit Website</a>
</div>
</li>
<?php endif; ?>
</ul>
</div>
<!-- Quick Contact Form Placeholder -->
<div class="sidebar-widget agent-quick-contact">
<h3 class="widget-title">Send a Message</h3>
<p class="widget-note">Interested in working with <?php the_title(); ?>? Get in touch today.</p>
<a href="<?php echo esc_url(home_url('/contact/')); ?>?agent=<?php echo esc_attr(get_the_title()); ?>" class="btn btn-primary btn-block">Contact Agent</a>
</div>
</aside>
</div>
</div>
</main>
<?php
endwhile;
get_footer();