Files
homeproz/wp-content/themes/homeproz/inc/template-functions.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

185 lines
4.7 KiB
PHP
Executable File

<?php
/**
* Template Helper Functions
*
* @package HomeProz
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Get the page-specific body class
*
* Returns the appropriate class name for the current page/template
* Used for page-scoped CSS and JavaScript
*
* @return string The page class name
*/
function homeproz_get_page_class() {
if (is_front_page()) {
return 'Home_Page';
}
if (is_home()) {
return 'Blog_Archive';
}
if (is_post_type_archive('property')) {
return 'Properties_Archive';
}
if (is_singular('property')) {
return 'Single_Property';
}
if (is_singular('post')) {
return 'Single_Post';
}
if (is_page_template('page-about.php') || is_page('about')) {
return 'About_Page';
}
if (is_page_template('page-contact.php') || is_page('contact')) {
return 'Contact_Page';
}
if (is_search()) {
return 'Search_Page';
}
if (is_404()) {
return 'Error_404';
}
if (is_archive()) {
return 'Archive_Page';
}
if (is_page()) {
return 'Default_Page';
}
return 'Default_Page';
}
/**
* Add page class to body classes
*/
function homeproz_body_classes($classes) {
$classes[] = homeproz_get_page_class();
// Add class if no sidebar
if (!is_active_sidebar('sidebar-blog') || is_front_page() || is_page()) {
$classes[] = 'no-sidebar';
}
return $classes;
}
add_filter('body_class', 'homeproz_body_classes');
/**
* Custom excerpt length
*/
function homeproz_excerpt_length($length) {
return 25;
}
add_filter('excerpt_length', 'homeproz_excerpt_length');
/**
* Custom excerpt more
*/
function homeproz_excerpt_more($more) {
return '&hellip;';
}
add_filter('excerpt_more', 'homeproz_excerpt_more');
/**
* Get property status badge class
*
* @param string $status The property status
* @return string CSS class for the badge
*/
function homeproz_get_status_class($status) {
$status = strtolower($status);
switch ($status) {
case 'active':
return 'badge-success';
case 'pending':
return 'badge-warning';
case 'sold':
return 'badge-muted';
default:
return 'badge-default';
}
}
/**
* Format price for display
*
* @param int|float $price The price value
* @return string Formatted price
*/
function homeproz_format_price($price) {
if (empty($price) || $price <= 0) {
return 'Contact for Price';
}
return '$' . number_format($price);
}
/**
* Fallback menu when no menu is assigned
*/
function homeproz_fallback_menu() {
echo '<ul class="nav-menu">';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/')) . '">Home</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/properties/')) . '">Properties</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/about/')) . '">About</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/contact/')) . '">Contact</a></li>';
echo '</ul>';
}
/**
* Fallback footer menu when no menu is assigned
*/
function homeproz_footer_fallback_menu() {
echo '<ul class="footer-menu">';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/')) . '">Home</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/properties/')) . '">Properties</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(get_post_type_archive_link('agent')) . '">Agents</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/about/')) . '">About</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/blog/')) . '">Blog</a></li>';
echo '<li class="menu-item"><a href="' . esc_url(home_url('/contact/')) . '">Contact</a></li>';
echo '</ul>';
}
/**
* Get theme option from ACF or defaults
*
* @param string $key Option key
* @param mixed $default Default value
* @return mixed Option value
*/
function homeproz_get_option($key, $default = '') {
// Use ACF helper if available
if (function_exists('homeproz_get_acf_option')) {
return homeproz_get_acf_option($key, $default);
}
// Fallback defaults
$options = array(
'phone' => '507-516-4870',
'email' => 'info@homeprozrealestate.com',
'address' => '111 E Clark St, Albert Lea, MN 56007',
'facebook' => 'https://www.facebook.com/profile.php?id=61578834743321',
'tiktok' => 'https://www.tiktok.com/@homeproz.real.est',
);
return isset($options[$key]) ? $options[$key] : $default;
}