feature: Update stock templates

This commit is contained in:
Keith Solomon
2025-02-12 08:08:35 -06:00
parent fd16680781
commit f74fb57358
4 changed files with 111 additions and 16 deletions

View File

@@ -5,10 +5,12 @@ $resource_types = get_terms(['taxonomy' => 'resource_type', 'hide_empty' => t
$resource_subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' => true]);
?>
<!-- Theme override -->
<form id="resource-filter">
<!-- Search Field -->
<!-- Search Field-->
<div class="search-text">
<input type="text" id="search" name="search" placeholder="Search resources..." class="full-width">
<input class="full-width" type="text" id="search" name="search" placeholder="Search resources..." value="<?php echo isset($_GET['search']) ? esc_attr($_GET['search']) : ''; ?>">
<button type="submit">Filter</button>
</div>
@@ -20,7 +22,8 @@ $resource_subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' =
<div class="filter-options">
<?php foreach ($resource_types as $type) : ?>
<label>
<input type="checkbox" name="resource_type[]" value="<?php echo esc_attr($type->slug); ?>">
<input type="checkbox" name="resource_type[]" value="<?php echo esc_attr($type->slug); ?>"
<?php echo (isset($_POST['resource_type']) && $_POST['resource_type'] === $type->slug) ? 'checked' : ''; ?>>
<?php echo esc_html($type->name); ?>
</label>
<?php endforeach; ?>

View File

@@ -1,12 +1,12 @@
<?php if (!defined('ABSPATH')) { exit; } ?>
<form id="homepage-filter" action="<?php echo site_url('/browse-resources/'); ?>" method="GET">
<form class="flex w-full" id="homepage-filter" action="<?php echo site_url('/browse-resources/'); ?>" method="POST">
<?php
$resource_types = get_terms(['taxonomy' => 'resource_type']);
if (!empty($resource_types)) :
?>
<select name="resource_type">
<select class="w-fit" name="resource_type">
<option value="">All Types</option>
<?php foreach ($resource_types as $type) : ?>
<option value="<?php echo esc_attr($type->slug); ?>"><?php echo esc_html($type->name); ?></option>
@@ -14,7 +14,7 @@
</select>
<?php endif; ?>
<input type="text" name="search" placeholder="Search resources...">
<input class="full-width" type="text" name="search" placeholder="Search resources...">
<button type="submit">Search</button>
<button class="btn btn-primary" type="submit">Search</button>
</form>

View File

@@ -1,8 +1,77 @@
<?php
if (!defined('ABSPATH')) { exit; } // Prevent direct access
error_log('Filter Summary: ' . print_r($_POST, true));
// Get count from AJAX or direct POST
$count = isset($resTotal) ? esc_html($resTotal) : 0;
// Initialize filters array
$filters = [];
// Handle the "Search" filter
if (!empty($_POST['search'])) {
$filters[] = [
'type' => 'search',
'value' => esc_html($_POST['search']),
'label' => '<strong>Search:</strong> "' . esc_html($_POST['search']) . '"'
];
}
// Handle the "Resource Type" filter
if (!empty($_POST['resource_type'])) {
$selected_types = is_array($_POST['resource_type']) ? $_POST['resource_type'] : [$_POST['resource_type']];
$filters[] = [
'type' => 'resource_type',
'value' => esc_html(implode(',', $selected_types)),
'label' => '<strong>Type:</strong> ' . esc_html(implode(', ', $selected_types))
];
}
// Handle the "Resource Subject" filter
if (!empty($_POST['resource_subject'])) {
$selected_subjects = is_array($_POST['resource_subject']) ? $_POST['resource_subject'] : [$_POST['resource_subject']];
$filters[] = [
'type' => 'resource_subject',
'value' => esc_html(implode(',', $selected_subjects)),
'label' => '<strong>Subject:</strong> ' . esc_html(implode(', ', $selected_subjects))
];
}
// Display filters as HTML
$filter_html = '';
if (!empty($filters)) {
foreach ($filters as $filter) {
$filter_html .= '<span class="filter-item" data-type="' . esc_attr($filter['type']) . '" data-value="' . esc_attr($filter['value']) . '">'
. $filter['label']
. ' <button class="remove-filter" aria-label="Remove ' . esc_attr($filter['type']) . '">×</button>'
. '</span> ';
}
} else {
$filter_html = 'None';
}
?>
<div id="resource-filter-summary">
<p><strong>Showing <span id="result-count"><?php echo isset($resTotal) ? esc_html($resTotal) : 0; ?></span> resources</strong></p>
<p><strong>Filters applied:</strong><br><span id="applied-filters">None</span></p>
<div id="resource-filter-summary" class="flex justify-between w-full">
<!-- Resource Count -->
<p><strong>Showing <span id="result-count"><?php echo esc_html($count); ?></span> resource(s)</strong></p>
<div class="sort-filters flex items-start gap-4">
<!-- Sort Container -->
<div id="sort-container">
<label for="sort-order">Sort by:</label>
<select id="sort-order">
<option value="date_desc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : '', 'date_desc'); ?>>Newest First</option>
<option value="date_asc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : '', 'date_asc'); ?>>Oldest First</option>
<option value="title_asc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : '', 'title_asc'); ?>>Title (A-Z)</option>
<option value="title_desc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : '', 'title_desc'); ?>>Title (Z-A)</option>
</select>
</div>
<!-- Applied Filters -->
<p>
<strong>Filters applied:</strong><br>
<span id="applied-filters"><?php echo $filter_html; ?></span>
</p>
</div>
</div>

View File

@@ -1,14 +1,37 @@
<?php
if (!defined('ABSPATH')) { exit; } // Prevent direct access
if (!empty($resources)) : ?>
<?php
if (!empty($resources)) :
foreach ($resources as $resource) :
$post_id = $resource->ID;
$post_title = get_the_title($post_id);
$post_link = get_permalink($post_id);
$postID = $resource->ID;
$postTitle = get_the_title($postID);
$postLink = get_permalink($postID);
?>
<div class="resource-item"><a href="<?php echo esc_url($post_link); ?>"><?php echo esc_html($post_title); ?></a></div>
<div class="resource-item border border-primary-500 p-4 rounded">
<h3 class="text-22px font-semibold leading-2 my-0 py-0"><a class="text-indigo-400" href="<?php echo esc_url($postLink); ?>"><?php echo esc_html($postTitle); ?></a></h3>
<div class="flex flex-col mt-8">
<p class="text-14px leading-tight my-0 py-0"><strong>Resource Type:</strong> <?php echo esc_html(get_the_terms($postID, 'resource_type')[0]->name); ?></p>
<p class="text-14px leading-tight my-0 py-0">
<strong>Resource Subject(s):</strong>
<?php
$subjects = get_the_terms($postID, 'resource_subject');
$count = count($subjects);
$i = 1;
foreach ($subjects as $subject) {
if ($i === $count) {
echo esc_html($subject->name);
} else {
echo esc_html($subject->name) . ', ';
}
$i++;
}
?>
</p>
</div>
</div>
<?php endforeach; ?>
<?php else : ?>
<p>No resources found.</p>