✨feature: Split summary to separate template
This commit is contained in:
@@ -18,7 +18,7 @@ jQuery(document).ready(function ($) {
|
||||
if (selectedTypes.length > 0) appliedFilters.push(`<strong>Type:</strong> ${selectedTypes.join(', ')}`);
|
||||
if (selectedSubjects.length > 0) appliedFilters.push(`<strong>Subject:</strong> ${selectedSubjects.join(', ')}`);
|
||||
|
||||
$('#applied-filters').html(appliedFilters.length ? appliedFilters.join(' | ') : 'None');
|
||||
$('#applied-filters').html(appliedFilters.length ? appliedFilters.join('<br>') : 'None');
|
||||
|
||||
let formData = {
|
||||
action: 'filter_resources',
|
||||
@@ -36,7 +36,11 @@ jQuery(document).ready(function ($) {
|
||||
response = JSON.parse(response);
|
||||
|
||||
$('#resource-results').html(response.html);
|
||||
$('#result-count').text(response.count);
|
||||
if (response.count !== undefined) {
|
||||
$('#result-count').text(response.count);
|
||||
} else {
|
||||
$('#result-count').text($('#result-count').text()); // Keep initial count
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,9 +57,11 @@
|
||||
#resource-filter-summary {
|
||||
display: flex;
|
||||
gap: .5rem;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1.25rem;
|
||||
width: 100%;
|
||||
|
||||
p { margin: 0; }
|
||||
p { margin: 0; padding: 0; }
|
||||
}
|
||||
|
||||
#resource-results {
|
||||
|
||||
@@ -63,22 +63,29 @@ class ResourceFilterPlugin {
|
||||
public function renderFilterForm() {
|
||||
ob_start();
|
||||
|
||||
$template = rfGetTemplate('filter-form.php');
|
||||
$query = new WP_Query([
|
||||
'post_type' => 'resource',
|
||||
'posts_per_page' => -1,
|
||||
]);
|
||||
|
||||
if ($template) {
|
||||
include_once $template;
|
||||
$resTotal = $query->found_posts; // Get the count of published resources
|
||||
|
||||
$resForm = rfGetTemplate('filter-form.php');
|
||||
$summary = rfGetTemplate('filter-summary.php');
|
||||
|
||||
if ($resForm) {
|
||||
include_once $resForm;
|
||||
} else {
|
||||
echo '<p>Error: Template not found.</p>';
|
||||
echo '<p>Error: Form template not found.</p>';
|
||||
}
|
||||
|
||||
$total_resources = wp_count_posts('resource')->publish; // Get the count of published resources
|
||||
if ($summary) {
|
||||
include_once $summary;
|
||||
}else {
|
||||
echo '<p>Error: Summary template not found.</p>';
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="resource-filter-summary">
|
||||
<strong>Showing <span id="result-count"><?php echo $total_resources; ?></span> resources</strong>
|
||||
<p><strong>Filters applied:</strong> <span id="applied-filters">None</span></p>
|
||||
</div>
|
||||
|
||||
<div id="resource-results">
|
||||
<?php $this->loadResources(); ?>
|
||||
</div>
|
||||
@@ -103,10 +110,10 @@ class ResourceFilterPlugin {
|
||||
$query = new WP_Query($query_args);
|
||||
$resources = $query->posts;
|
||||
|
||||
$template = rfGetTemplate('resource-results.php');
|
||||
$resResults = rfGetTemplate('resource-results.php');
|
||||
|
||||
if ($template) {
|
||||
include_once $template;
|
||||
if ($resResults) {
|
||||
include_once $resResults;
|
||||
} else {
|
||||
echo '<p>Error: Results template not found.</p>';
|
||||
}
|
||||
@@ -166,10 +173,11 @@ class ResourceFilterPlugin {
|
||||
ob_start();
|
||||
|
||||
$resources = $query->posts;
|
||||
$template = rfGetTemplate('resource-results.php');
|
||||
|
||||
if ($template) {
|
||||
include_once $template;
|
||||
$resResults = rfGetTemplate('resource-results.php');
|
||||
|
||||
if ($resResults) {
|
||||
include_once $resResults;
|
||||
} else {
|
||||
echo '<p>Error: Results template not found.</p>';
|
||||
}
|
||||
|
||||
8
templates/filter-summary.php
Normal file
8
templates/filter-summary.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) { exit; } // Prevent direct access
|
||||
?>
|
||||
|
||||
<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>
|
||||
Reference in New Issue
Block a user