Compare commits
17 Commits
2025032516
...
2025.03.29
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf70df2513 | ||
|
|
71b8d4261f | ||
|
|
733d5c3fec | ||
|
|
d5c8686fd5 | ||
|
|
a983351446 | ||
|
|
22b6e37331 | ||
|
|
ad2034a833 | ||
|
|
6cb02fdf54 | ||
|
|
e8b0116ace | ||
|
|
50a6164576 | ||
|
|
dd5625ded9 | ||
|
|
4014b2fd4a | ||
|
|
e8d8c56224 | ||
|
|
a6617bf35a | ||
|
|
0ed7a7ad01 | ||
|
|
44111b4ee4 | ||
|
|
4600a52a1c |
@@ -1,35 +1,78 @@
|
||||
name: Add release
|
||||
run-name: Add release with Gitea Actions
|
||||
run-name: Add tagged release with Github Actions
|
||||
on: [push]
|
||||
# on: [workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
CreateRelease:
|
||||
name: Create release
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ !contains(gitea.event.head_commit.message, '#skipGA') && contains(gitea.event.head_commit.message, '#release') }}
|
||||
if: ${{ contains(github.event.head_commit.message, '#release') && !contains(github.event.head_commit.message, '#skipGA') }}
|
||||
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Generate trunkver
|
||||
id: trunkver
|
||||
uses: https://github.com/crftd-tech/trunkver@main
|
||||
- name: Get current date
|
||||
id: get-date
|
||||
run: |
|
||||
echo "date=$(date +'%Y.%m.%d')" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Get tag
|
||||
uses: https://github.com/little-core-labs/get-git-tag@v3.0.1
|
||||
id: tagName
|
||||
- name: Use tag
|
||||
run: echo ${{steps.tagName.outputs.tag}}
|
||||
- name: Generate release tag
|
||||
id: release-tag
|
||||
run: |
|
||||
DATE="${{ steps.get-date.outputs.date }}"
|
||||
TAG_PREFIX="$DATE"
|
||||
|
||||
# Find existing tags for the date
|
||||
EXISTING=$(git tag | grep "^$TAG_PREFIX-" || true)
|
||||
|
||||
if [ -z "$EXISTING" ]; then
|
||||
SERIAL=1
|
||||
else
|
||||
SERIAL=$(echo "$EXISTING" | sed "s/^$TAG_PREFIX-//" | sort -nr | head -n1)
|
||||
SERIAL=$((SERIAL + 1))
|
||||
fi
|
||||
|
||||
NEW_TAG="$TAG_PREFIX-$SERIAL"
|
||||
echo "tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Show new tag
|
||||
run: |
|
||||
echo "Tag to be created: ${{ steps.release-tag.outputs.tag }}"
|
||||
|
||||
- name: Extract latest changelog entry and version
|
||||
id: extract-changelog
|
||||
run: |
|
||||
version=$(awk '/^## /{ print $2; exit }' CHANGELOG.md)
|
||||
changelog=$(awk '/^## /{i++} i==1{print}' CHANGELOG.md)
|
||||
|
||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||
echo "changelog<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$changelog" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create renamed zip file
|
||||
run: |
|
||||
REPO_NAME=$(basename -s .git `git config --get remote.origin.url`)
|
||||
VERSION=${{ steps.extract-changelog.outputs.version }}
|
||||
ZIP_NAME="${REPO_NAME}-${VERSION}.zip"
|
||||
|
||||
# Create a temporary clone without .git
|
||||
mkdir package
|
||||
git archive --format=zip HEAD -o "$ZIP_NAME"
|
||||
|
||||
echo "zip_name=$ZIP_NAME" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: https://github.com/comnoco/create-release-action@v2
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ steps.release-tag.outputs.tag }}
|
||||
name: Release ${{ steps.release-tag.outputs.tag }}
|
||||
body: ${{ steps.extract-changelog.outputs.changelog }}
|
||||
files: ${{ env.zip_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.trunkver.outputs.trunkver }}
|
||||
release_name: Release ${{ steps.trunkver.outputs.trunkver }}
|
||||
body: |
|
||||
${{ gitea.event.head_commit.message}}
|
||||
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
bak/
|
||||
@@ -13,7 +13,7 @@ The Content Filter Plugin is a WordPress plugin designed to enhance content disc
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone this repo or download the plugin files and place them in the `wp-content/plugins/resource-filter` directory.
|
||||
1. Clone this repo or download the [latest release](https://github.com/Vincent-Design-Inc/resource-filter/releases) and place them in the `wp-content/plugins/resource-filter` directory.
|
||||
2. Log in to your WordPress admin dashboard.
|
||||
3. Navigate to **Plugins** > **Installed Plugins**.
|
||||
4. Activate the **Content Filter** plugin.
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
/** Triggers filtering and pagination of resources based on the current form state.
|
||||
*
|
||||
* @param {number} [paged=1] - The page number to query.
|
||||
*/
|
||||
function triggerFiltering(paged = 1) {
|
||||
let searchTerm = $('#search').val();
|
||||
|
||||
let selectedTypes = $('input[name="resource_type[]"]:checked')
|
||||
.map(function () {
|
||||
return $(this).closest('label').text().trim();
|
||||
})
|
||||
.get();
|
||||
|
||||
let selectedSubjects = $('input[name="resource_subject[]"]:checked')
|
||||
.map(function () {
|
||||
return $(this).closest('label').text().trim();
|
||||
})
|
||||
.get();
|
||||
|
||||
let appliedFilters = [];
|
||||
|
||||
// Search Term
|
||||
if (searchTerm) {
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="search" data-value="${searchTerm}">
|
||||
<strong>Search:</strong> "${searchTerm}"
|
||||
<button class="remove-filter" aria-label="Remove Search">×</button>
|
||||
</span>`
|
||||
);
|
||||
}
|
||||
|
||||
// Resource Types
|
||||
$('input[name="resource_type[]"]:checked').each(function () {
|
||||
const slug = $(this).val(); // Get the slug
|
||||
const name = $(this).closest('label').text().trim(); // Get the name
|
||||
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="resource_type" data-value="${slug}">
|
||||
<strong>Type:</strong> ${name}
|
||||
<button class="remove-filter" aria-label="Remove Type ${name}">×</button>
|
||||
</span>`
|
||||
);
|
||||
});
|
||||
|
||||
// Resource Subjects
|
||||
selectedSubjects.forEach(function (subject) {
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="resource_subject" data-value="${subject}">
|
||||
<strong>Subject:</strong> ${subject}
|
||||
<button class="remove-filter" aria-label="Remove Subject ${subject}">×</button>
|
||||
</span>`
|
||||
);
|
||||
});
|
||||
|
||||
$('#applied-filters').html(
|
||||
appliedFilters.length ? appliedFilters.join(' ') : 'None'
|
||||
);
|
||||
|
||||
let formData = {
|
||||
action: 'filter_resources',
|
||||
nonce: resourceFilterAjax.nonce,
|
||||
search: $('#search').val(),
|
||||
resource_type: $('input[name="resource_type[]"]:checked')
|
||||
.map(function () {
|
||||
return this.value;
|
||||
})
|
||||
.get(),
|
||||
resource_subject: $('input[name="resource_subject[]"]:checked')
|
||||
.map(function () {
|
||||
return this.value;
|
||||
})
|
||||
.get(),
|
||||
sort_order: $('#sort-order').val(),
|
||||
paged: paged,
|
||||
};
|
||||
|
||||
$.post(resourceFilterAjax.ajaxurl, formData, function (response) {
|
||||
response = JSON.parse(response);
|
||||
|
||||
$('#resource-results').html(response.html);
|
||||
$('#result-count').text(response.count);
|
||||
|
||||
// Update pagination
|
||||
if (response.pagination && response.pagination.length > 0) {
|
||||
// Clear and update pagination container
|
||||
if (!$('.pagination').length) {
|
||||
$('#resource-results').after('<div class="pagination"></div>');
|
||||
}
|
||||
$('.pagination').html(response.pagination.join(''));
|
||||
} else {
|
||||
$('.pagination').html(''); // Clear pagination if no links are needed
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Handle filter removal
|
||||
$(document).on('click', '.remove-filter', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
let $filter = $(this).closest('.filter-item');
|
||||
let filterType = $filter.data('type');
|
||||
let filterValue = $filter.data('value');
|
||||
|
||||
// Remove the corresponding filter
|
||||
if (filterType === 'search') {
|
||||
$('#search').val('');
|
||||
} else if (filterType === 'resource_type') {
|
||||
$('input[name="resource_type[]"]:checked').each(function () {
|
||||
if ($(this).val() === filterValue) { // Match the slug, not the name
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
} else if (filterType === 'resource_subject') {
|
||||
$('input[name="resource_subject[]"]:checked').each(function () {
|
||||
if ($(this).closest('label').text().trim() === filterValue) {
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Re-trigger filtering after removing the filter
|
||||
triggerFiltering(1);
|
||||
});
|
||||
|
||||
// Handle form submission
|
||||
$('#resource-filter').on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
triggerFiltering();
|
||||
});
|
||||
|
||||
// Handle sort order change
|
||||
$('#sort-order').on('change', function () {
|
||||
triggerFiltering();
|
||||
});
|
||||
|
||||
// Handle pagination click
|
||||
$(document).on('click', '.pagination a', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Extract the page number from the link
|
||||
let pagedMatch = $(this).attr('href').match(/paged=(\d+)/);
|
||||
let paged = pagedMatch ? pagedMatch[1] : 1; // Default to page 1 if no match is found
|
||||
|
||||
// Trigger filtering for the selected page
|
||||
triggerFiltering(paged);
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Toggle dropdown visibility
|
||||
document.querySelectorAll('.custom-dropdown .dropdown-toggle').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
const dropdown = this.parentElement;
|
||||
|
||||
// Close all other dropdowns
|
||||
document.querySelectorAll('.custom-dropdown').forEach(function (otherDropdown) {
|
||||
if (otherDropdown !== dropdown) {
|
||||
otherDropdown.classList.remove('open');
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle the current dropdown
|
||||
dropdown.classList.toggle('open');
|
||||
});
|
||||
});
|
||||
|
||||
// Close dropdowns when clicking outside
|
||||
document.addEventListener('click', function (event) {
|
||||
if (!event.target.closest('.custom-dropdown')) {
|
||||
document.querySelectorAll('.custom-dropdown').forEach(function (dropdown) {
|
||||
dropdown.classList.remove('open');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
130
assets/script.js
130
assets/script.js
@@ -8,91 +8,80 @@ jQuery(document).ready(function ($) {
|
||||
*/
|
||||
function triggerFiltering(paged = 1) {
|
||||
let searchTerm = $('#search').val();
|
||||
let appliedFilters = [];
|
||||
|
||||
let appliedFilters = [];
|
||||
let typeFilters = [];
|
||||
let subjectFilters = [];
|
||||
|
||||
let selectedTypes = $('input[name="resource_type[]"]:checked')
|
||||
.map(function () {
|
||||
return $(this).closest('label').text().trim();
|
||||
})
|
||||
.get();
|
||||
|
||||
let selectedSubjects = $('input[name="resource_subject[]"]:checked')
|
||||
.map(function () {
|
||||
return $(this).closest('label').text().trim();
|
||||
})
|
||||
.get();
|
||||
|
||||
// Search Term
|
||||
if (searchTerm) {
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="search" data-value="${searchTerm}">
|
||||
<strong>Search:</strong> "${searchTerm}"
|
||||
<button class="remove-filter" aria-label="Remove Search">×</button>
|
||||
<strong>Search:</strong> ${searchTerm}
|
||||
<button class="remove-filter" aria-label="Remove search term">×</button>
|
||||
</span>`
|
||||
);
|
||||
}
|
||||
|
||||
// Resource Types
|
||||
$('input[name="resource_type[]"]:checked').each(function () {
|
||||
const slug = $(this).val(); // Get the slug
|
||||
const name = $(this).closest('label').text().trim(); // Get the name
|
||||
// Collect selected taxonomy filters dynamically
|
||||
let taxonomyFilters = {};
|
||||
$('input[type="checkbox"]:checked').each(function () {
|
||||
let taxonomy = $(this).attr('name').replace('[]', ''); // Extract taxonomy name
|
||||
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="resource_type" data-value="${slug}">
|
||||
<strong>Type:</strong> ${name}
|
||||
<button class="remove-filter" aria-label="Remove ${name}">×</button>
|
||||
</span>`
|
||||
);
|
||||
if (!taxonomyFilters[taxonomy]) {
|
||||
taxonomyFilters[taxonomy] = [];
|
||||
}
|
||||
|
||||
typeFilters.push(
|
||||
`${name}`
|
||||
);
|
||||
taxonomyFilters[taxonomy].push({
|
||||
value: $(this).val(),
|
||||
text: $(this).closest('label').text().trim() // Get the text associated with the checkbox
|
||||
});
|
||||
});
|
||||
|
||||
// Resource Subjects
|
||||
selectedSubjects.forEach(function (subject) {
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="resource_subject" data-value="${subject}">
|
||||
<strong>Subject:</strong> ${subject}
|
||||
<button class="remove-filter" aria-label="Remove ${subject}">×</button>
|
||||
</span>`
|
||||
);
|
||||
const toTitleCase = (phrase) => {
|
||||
return phrase
|
||||
.toLowerCase()
|
||||
.split('_')
|
||||
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
subjectFilters.push(
|
||||
`${subject}`
|
||||
);
|
||||
});
|
||||
// Build applied filters for display
|
||||
let dropdownFilters = [];
|
||||
let finalFilters = {};
|
||||
|
||||
$('#applied-filters').html(
|
||||
appliedFilters.length ? appliedFilters.join(' ') : 'None'
|
||||
);
|
||||
for (let taxonomy in taxonomyFilters) {
|
||||
taxonomyFilters[taxonomy].forEach(function (term) {
|
||||
let taxName = toTitleCase(taxonomy);
|
||||
|
||||
$('#type_text').html(
|
||||
typeFilters.length ? typeFilters.join(', ') : 'Resource Type'
|
||||
);
|
||||
$('#subject_text').html(
|
||||
subjectFilters.length ? subjectFilters.join(', ') : 'Subject Tags'
|
||||
);
|
||||
appliedFilters.push(
|
||||
`<span class="filter-item" data-type="${taxonomy}" data-value="${term.value}">
|
||||
<strong>${taxName}:</strong> ${term.text}
|
||||
<button class="remove-filter" aria-label="Remove ${term.text}">×</button>
|
||||
</span>`
|
||||
);
|
||||
|
||||
dropdownFilters.push(term.text);
|
||||
|
||||
if (!finalFilters[taxonomy]) {
|
||||
finalFilters[taxonomy] = [];
|
||||
}
|
||||
|
||||
finalFilters[taxonomy].push(
|
||||
term.value,
|
||||
);
|
||||
|
||||
$(`#${taxonomy}_text`).html(
|
||||
dropdownFilters ? dropdownFilters.join(', ') : taxName
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
$('#applied-filters').html(appliedFilters.length ? appliedFilters.join(' ') : 'None');
|
||||
|
||||
let formData = {
|
||||
action: 'filter_resources',
|
||||
nonce: resourceFilterAjax.nonce,
|
||||
search: searchTerm,
|
||||
paged: paged,
|
||||
sort_order: $('#sort-order').val(),
|
||||
resource_type: $('input[name="resource_type[]"]:checked')
|
||||
.map(function () {
|
||||
return this.value;
|
||||
})
|
||||
.get(),
|
||||
resource_subject: $('input[name="resource_subject[]"]:checked')
|
||||
.map(function () {
|
||||
return this.value;
|
||||
})
|
||||
.get(),
|
||||
sort_order: $('#sortOrder').val(),
|
||||
...finalFilters, // Include taxonomy filters dynamically
|
||||
};
|
||||
|
||||
// Perform AJAX request
|
||||
@@ -112,7 +101,7 @@ jQuery(document).ready(function ($) {
|
||||
}
|
||||
|
||||
// Handle sort order change
|
||||
$('#sort-order').on('change', function () {
|
||||
$('#sortOrder').on('change', function () {
|
||||
triggerFiltering();
|
||||
});
|
||||
|
||||
@@ -148,18 +137,13 @@ jQuery(document).ready(function ($) {
|
||||
// Remove the corresponding filter
|
||||
if (filterType === 'search') {
|
||||
$('#search').val('');
|
||||
} else if (filterType === 'resource_type') {
|
||||
$('input[name="resource_type[]"]:checked').each(function () {
|
||||
} else {
|
||||
// Dynamically handle taxonomy filters
|
||||
$(`input[name="${filterType}[]"]:checked`).each(function () {
|
||||
if ($(this).val() === filterValue) { // Match the slug, not the name
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
} else if (filterType === 'resource_subject') {
|
||||
$('input[name="resource_subject[]"]:checked').each(function () {
|
||||
if ($(this).closest('label').text().trim() === filterValue) {
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Re-trigger filtering after removing the filter
|
||||
|
||||
@@ -67,13 +67,13 @@ class ContentFilterPlugin {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
check_admin_referer('content_filter_settings');
|
||||
|
||||
$post_types = isset($_POST['post_types']) ? array_map('sanitize_text_field', $_POST['post_types']) : [];
|
||||
$postTypes = isset($_POST['post_types']) ? array_map('sanitize_text_field', $_POST['post_types']) : [];
|
||||
$taxonomies = isset($_POST['taxonomies']) ? array_map('sanitize_text_field', $_POST['taxonomies']) : [];
|
||||
$posts_per_page = isset($_POST['posts_per_page']) ? intval($_POST['posts_per_page']) : 12;
|
||||
$homepage_taxonomy = isset($_POST['homepage_taxonomy']) ? sanitize_text_field($_POST['homepage_taxonomy']) : '';
|
||||
|
||||
update_option('content_filter_homepage_taxonomy', $homepage_taxonomy);
|
||||
update_option('content_filter_post_types', $post_types);
|
||||
update_option('content_filter_post_types', $postTypes);
|
||||
update_option('content_filter_taxonomies', $taxonomies);
|
||||
update_option('content_filter_posts_per_page', $posts_per_page);
|
||||
|
||||
@@ -81,7 +81,7 @@ class ContentFilterPlugin {
|
||||
}
|
||||
|
||||
// Get saved options
|
||||
$post_types = get_option('content_filter_post_types', []);
|
||||
$postTypes = get_option('content_filter_post_types', []);
|
||||
$taxonomies = get_option('content_filter_taxonomies', []);
|
||||
$posts_per_page = get_option('content_filter_posts_per_page', 12);
|
||||
$homepage_taxonomy = get_option('content_filter_homepage_taxonomy', '');
|
||||
@@ -99,7 +99,7 @@ class ContentFilterPlugin {
|
||||
<p>Select the post types to include in the filter.</p>
|
||||
<?php foreach ($all_post_types as $post_type): ?>
|
||||
<label>
|
||||
<input type="checkbox" name="post_types[]" value="<?php echo esc_attr($post_type->name); ?>" <?php checked(in_array($post_type->name, $post_types)); ?>>
|
||||
<input type="checkbox" name="post_types[]" value="<?php echo esc_attr($post_type->name); ?>" <?php checked(in_array($post_type->name, $postTypes)); ?>>
|
||||
<?php echo esc_html($post_type->labels->singular_name); ?>
|
||||
</label><br>
|
||||
<?php endforeach; ?>
|
||||
@@ -129,7 +129,7 @@ class ContentFilterPlugin {
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<p><input type="submit" class="button-primary" value="Save Settings"></p>
|
||||
<p style="margin-top: 1.5rem;"><input type="submit" class="button-primary" value="Save Settings"></p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
@@ -153,7 +153,7 @@ class ContentFilterPlugin {
|
||||
wp_enqueue_style('content-filter-style', $theme_stylesheet_url, [], filemtime($theme_stylesheet));
|
||||
} else {
|
||||
// Fall back to the plugin's stylesheet
|
||||
wp_enqueue_style('content-filter-style', plugins_url('assets/style.css', __FILE__), [], filemtime(plugin_dir_path(__FILE__) . 'assets/style.css'));
|
||||
wp_enqueue_style('content-filter-style', plugins_url('templates/style.css', __FILE__), [], filemtime(plugin_dir_path(__FILE__) . 'templates/style.css'));
|
||||
}
|
||||
|
||||
// Load script only if the shortcode is present on the page
|
||||
@@ -184,7 +184,8 @@ class ContentFilterPlugin {
|
||||
|
||||
$query = $this->getQuery();
|
||||
|
||||
define('RF_TOTAL_RESOURCES', $query->found_posts);
|
||||
global $postsTotal;
|
||||
$postsTotal = $query->found_posts;
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -216,6 +217,7 @@ class ContentFilterPlugin {
|
||||
private function getTemplate($type) {
|
||||
if ($type === 'homepage') {
|
||||
$homepage_taxonomy = get_option('content_filter_homepage_taxonomy', '');
|
||||
|
||||
if (!empty($homepage_taxonomy) && taxonomy_exists($homepage_taxonomy)) {
|
||||
$GLOBALS['homepage_taxonomy'] = $homepage_taxonomy;
|
||||
return 'filter-homepage.php';
|
||||
@@ -290,56 +292,40 @@ class ContentFilterPlugin {
|
||||
* @return WP_Query The query object
|
||||
*/
|
||||
private function getQuery() {
|
||||
$postTypes = get_option('content_filter_post_types', ['post']); // Get selected post types from admin
|
||||
$postCount = get_option('content_filter_posts_per_page', 12); // Get posts per page from admin
|
||||
$strSearch = isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$sort_order = isset($_POST['sort_order']) ? sanitize_text_field($_POST['sort_order']) : 'date_desc';
|
||||
|
||||
$query_args = [
|
||||
'post_type' => get_option('content_filter_post_types', ['post']),
|
||||
'posts_per_page' => get_option('content_filter_posts_per_page', 12),
|
||||
'post_type' => $postTypes,
|
||||
'posts_per_page' => $postCount,
|
||||
'paged' => max(1, get_query_var('paged', 1)), // Get current page number
|
||||
'tax_query' => $this->buildDynamicTaxQuery(),
|
||||
's' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '',
|
||||
's' => $strSearch,
|
||||
];
|
||||
|
||||
// Sorting logic
|
||||
$query_args = $this->applySorting($query_args, $sort_order);
|
||||
|
||||
$tax_query = [];
|
||||
$query = new WP_Query($query_args);
|
||||
$query->set('count', $query->found_posts);
|
||||
|
||||
if (!empty($_POST['resource_type'])) {
|
||||
$resType = is_array($_POST['resource_type']) ? array_map('sanitize_text_field', $_POST['resource_type']) : sanitize_text_field($_POST['resource_type']);
|
||||
|
||||
$query_args['tax_query'][] = [
|
||||
'taxonomy' => 'resource_type',
|
||||
'field' => 'slug',
|
||||
'terms' => $resType,
|
||||
'operator' => 'IN'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($_POST['resource_subject'])) {
|
||||
$query_args['tax_query'][] = [
|
||||
'taxonomy' => 'resource_subject',
|
||||
'field' => 'slug',
|
||||
'terms' => array_map('sanitize_text_field', $_POST['resource_subject']),
|
||||
'operator' => 'IN'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($tax_query)) {
|
||||
$query_args['tax_query'] = [
|
||||
'relation' => 'AND', // Both filters must match
|
||||
...$tax_query
|
||||
];
|
||||
}
|
||||
|
||||
return new WP_Query($query_args);
|
||||
return $query;
|
||||
} else {
|
||||
return new WP_Query([
|
||||
'post_type' => get_option('content_filter_post_types', ['post']),
|
||||
'posts_per_page' => get_option('content_filter_posts_per_page', 12),
|
||||
$query = new WP_Query([
|
||||
'post_type' => $postTypes,
|
||||
'posts_per_page' => $postCount,
|
||||
'paged' => max(1, get_query_var('paged', 1)), // Get current page number
|
||||
'tax_query' => $this->buildDynamicTaxQuery(),
|
||||
's' => $strSearch,
|
||||
]);
|
||||
|
||||
$query->set('count', $query->found_posts);
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,27 +351,27 @@ class ContentFilterPlugin {
|
||||
switch ($sort_order) {
|
||||
case 'date_asc':
|
||||
$query_args['orderby'] = 'date';
|
||||
$query_args['order'] = 'ASC';
|
||||
$query_args['order'] = 'ASC';
|
||||
break;
|
||||
|
||||
case 'date_desc':
|
||||
$query_args['orderby'] = 'date';
|
||||
$query_args['order'] = 'DESC';
|
||||
$query_args['order'] = 'DESC';
|
||||
break;
|
||||
|
||||
case 'title_asc':
|
||||
$query_args['orderby'] = 'title';
|
||||
$query_args['order'] = 'ASC';
|
||||
$query_args['order'] = 'ASC';
|
||||
break;
|
||||
|
||||
case 'title_desc':
|
||||
$query_args['orderby'] = 'title';
|
||||
$query_args['order'] = 'DESC';
|
||||
$query_args['order'] = 'DESC';
|
||||
break;
|
||||
|
||||
default:
|
||||
$query_args['orderby'] = 'date';
|
||||
$query_args['order'] = 'DESC';
|
||||
$query_args['order'] = 'DESC';
|
||||
}
|
||||
|
||||
return $query_args;
|
||||
@@ -469,20 +455,21 @@ class ContentFilterPlugin {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function buildQueryArgs() {
|
||||
$post_types = get_option('content_filter_post_types', []);
|
||||
|
||||
$postTypes = get_option('content_filter_post_types', []);
|
||||
$postCount = get_option('content_filter_posts_per_page', 12); // Get posts per page from admin
|
||||
$strSearch = isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '';
|
||||
$sort_order = isset($_POST['sort_order']) ? sanitize_text_field($_POST['sort_order']) : 'date_desc';
|
||||
|
||||
$query_args = [
|
||||
'post_type' => !empty($post_types) ? $post_types : ['post'],
|
||||
'posts_per_page' => get_option('content_filter_posts_per_page', 12),
|
||||
'post_type' => !empty($postTypes) ? $postTypes : ['post'],
|
||||
'posts_per_page' => $postCount,
|
||||
'paged' => isset($_POST['paged']) ? intval($_POST['paged']) : 1, // Get current page number
|
||||
'tax_query' => $this->buildDynamicTaxQuery(),
|
||||
's' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '',
|
||||
's' => $strSearch,
|
||||
];
|
||||
|
||||
$query_args = $this->applySorting($query_args, $sort_order);
|
||||
$query_args['tax_query'] = $this->buildTaxQuery();
|
||||
$query_args['tax_query'] = $this->buildDynamicTaxQuery();
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
@@ -498,7 +485,7 @@ class ContentFilterPlugin {
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private function buildDynamicTaxQuery() {
|
||||
$taxonomies = get_option('content_filter_taxonomies', []);
|
||||
$taxonomies = get_option('content_filter_taxonomies', []); // Get selected taxonomies from admin
|
||||
$tax_query = [];
|
||||
|
||||
if (!empty($taxonomies)) {
|
||||
@@ -526,50 +513,6 @@ class ContentFilterPlugin {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** Builds a taxonomy query array for filtering resources by type and subject.
|
||||
*
|
||||
* Constructs a taxonomy query based on the 'resource_type' and 'resource_subject'
|
||||
* POST parameters. The function checks if these parameters are present and
|
||||
* properly sanitizes them before adding them to the query. If both parameters
|
||||
* are provided, the query will require both conditions to match using an 'AND'
|
||||
* relation.
|
||||
*
|
||||
* @return array The constructed tax query array, or an empty array if no filters are applied.
|
||||
*/
|
||||
|
||||
private function buildTaxQuery() {
|
||||
$tax_query = [];
|
||||
|
||||
if (!empty($_POST['resource_type'])) {
|
||||
$resType = is_array($_POST['resource_type']) ? array_map('sanitize_text_field', $_POST['resource_type']) : sanitize_text_field($_POST['resource_type']);
|
||||
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'resource_type',
|
||||
'field' => 'slug',
|
||||
'terms' => $resType,
|
||||
'operator' => 'IN'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($_POST['resource_subject'])) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'resource_subject',
|
||||
'field' => 'slug',
|
||||
'terms' => array_map('sanitize_text_field', $_POST['resource_subject']),
|
||||
'operator' => 'IN'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($tax_query)) {
|
||||
return [
|
||||
'relation' => 'AND', // Both filters must match
|
||||
...$tax_query
|
||||
];
|
||||
}
|
||||
|
||||
return $tax_query;
|
||||
}
|
||||
|
||||
/** Sends an AJAX response with resource filtering results.
|
||||
*
|
||||
* Constructs a response array containing the number of resources found,
|
||||
@@ -583,24 +526,31 @@ class ContentFilterPlugin {
|
||||
|
||||
private function sendAjaxResponse($query) {
|
||||
$response = [
|
||||
'count' => $query->found_posts,
|
||||
'filters' => [
|
||||
'search' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '',
|
||||
'resource_type' => !empty($_POST['resource_type']) ? sanitize_text_field($_POST['resource_type']) : '',
|
||||
'resource_subject' => !empty($_POST['resource_subject']) ? sanitize_text_field($_POST['resource_subject']) : ''
|
||||
'count' => $query->found_posts,
|
||||
'filters' => [
|
||||
'search' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '',
|
||||
],
|
||||
'html' => ob_get_clean(),
|
||||
'pagination' => paginate_links([
|
||||
'total' => $query->max_num_pages,
|
||||
'current' => isset($_POST['paged']) ? intval($_POST['paged']) : 1,
|
||||
'format' => '?paged=%#%',
|
||||
'add_args' => [], // Pass additional query arguments
|
||||
'html' => ob_get_clean(),
|
||||
'pagination' => paginate_links([
|
||||
'total' => $query->max_num_pages,
|
||||
'current' => isset($_POST['paged']) ? intval($_POST['paged']) : 1,
|
||||
'format' => '?paged=%#%',
|
||||
'add_args' => [], // Pass additional query arguments
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'type' => 'array',
|
||||
'type' => 'array',
|
||||
])
|
||||
];
|
||||
|
||||
// Include dynamic taxonomy filters in the response
|
||||
$taxonomies = get_option('content_filter_taxonomies', []);
|
||||
|
||||
foreach ($taxonomies as $taxonomy) {
|
||||
if (!empty($_POST[$taxonomy])) {
|
||||
$response['filters'][$taxonomy] = array_map('sanitize_text_field', (array) $_POST[$taxonomy]);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
wp_die();
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) { exit; } // Prevent direct access
|
||||
|
||||
$resource_types = get_terms(['taxonomy' => 'resource_type', 'hide_empty' => true]);
|
||||
$resource_subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' => true]);
|
||||
?>
|
||||
|
||||
<!-- Theme override -->
|
||||
<form id="resource-filter">
|
||||
<!-- Search Field-->
|
||||
<div class="search-text">
|
||||
<input class="full-width" type="text" id="search" name="search" placeholder="Search resources..." value="<?php echo isset($search) ? esc_attr($search) : ''; ?>">
|
||||
|
||||
<button type="reset" id="clear-search">×</button>
|
||||
<button type="submit">Filter</button>
|
||||
</div>
|
||||
|
||||
<div class="search-tax">
|
||||
<!-- Resource Type Filters -->
|
||||
<details>
|
||||
<summary>Resource Type</summary>
|
||||
|
||||
<div class="filter-options">
|
||||
<?php foreach ($resource_types as $type) : ?>
|
||||
<label>
|
||||
<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; ?>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<!-- Resource Subject Filters -->
|
||||
<details>
|
||||
<summary>Resource Subject</summary>
|
||||
|
||||
<div class="filter-options">
|
||||
<?php foreach ($resource_subjects as $subject) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="resource_subject[]" value="<?php echo esc_attr($subject->slug); ?>">
|
||||
<?php echo esc_html($subject->name); ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</form>
|
||||
@@ -1,59 +1,36 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) { exit; } // Prevent direct access
|
||||
|
||||
$resource_types = get_terms(['taxonomy' => 'resource_type', 'hide_empty' => true]);
|
||||
$resource_subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' => true]);
|
||||
$selected_taxonomies = get_option('content_filter_taxonomies', []); // Get selected taxonomies
|
||||
?>
|
||||
|
||||
<form class="px-4 sm:px-0" id="resource-filter">
|
||||
<!-- Search Field -->
|
||||
<!-- Search Field - Theme -->
|
||||
<div class="search-text">
|
||||
<input class="bg-[#F8F8F8] border-[#8B8B8B] border-2" type="text" id="search" name="search" placeholder="Search resources..."
|
||||
value="<?php echo isset($search) ? esc_attr($search) : ''; ?>">
|
||||
<button class="bg-[#3B65D4] text-white" type="submit">Search</button>
|
||||
<button type="reset" id="clear-search">×</button>
|
||||
<input class="bg-light border-secondary border-2 full-width" type="text" id="search" name="search" placeholder="Search..." value="<?php echo isset($search) ? esc_attr($search) : ''; ?>">
|
||||
<button class="bg-primary text-white" type="submit">Search</button>
|
||||
<button type="reset" class="bg-danger text-white" id="clear-search">×</button>
|
||||
</div>
|
||||
|
||||
<div class="search-tax">
|
||||
<!-- Resource Type Filters -->
|
||||
<div class="custom-dropdown">
|
||||
<button type="button" class="dropdown-toggle">Resource Type</button>
|
||||
<div class="dropdown-menu">
|
||||
<?php foreach ($resource_types as $type) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="resource_type[]" value="<?php echo esc_attr($type->slug); ?>" <?php echo
|
||||
(isset($_POST['resource_type']) && in_array($type->slug, (array) $_POST['resource_type'])) ? 'checked' :
|
||||
'';
|
||||
?>>
|
||||
<?php echo esc_html($type->name); ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
foreach ($selected_taxonomies as $taxonomy):
|
||||
$terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => true]);
|
||||
$taxonomy_obj = get_taxonomy($taxonomy);
|
||||
|
||||
<!-- Resource Subject Filters -->
|
||||
<div class="custom-dropdown">
|
||||
<button type="button" class="dropdown-toggle">Resource Subject</button>
|
||||
<div class="dropdown-menu">
|
||||
<?php foreach ($resource_subjects as $subject) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="resource_subject[]" value="<?php echo esc_attr($subject->slug); ?>" <?php echo
|
||||
(isset($_POST['resource_subject']) && in_array($subject->slug, (array) $_POST['resource_subject'])) ?
|
||||
'checked' : ''; ?>>
|
||||
<?php echo esc_html($subject->name); ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Sort Container -->
|
||||
<div id="sort-container" class="flex items-start">
|
||||
<label class="pt-2" for="sort-order">Sort:</label>
|
||||
<select class="ml-2 bg-white border-[#CCC] border-2" id="sort-order">
|
||||
<option value="date_desc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : 'date_desc', 'date_desc'); ?>>Newest First</option>
|
||||
<option value="date_asc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : 'date_desc', 'date_asc'); ?>>Oldest First</option>
|
||||
<option value="title_asc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : 'date_desc', 'title_asc'); ?>>Title (A-Z)</option>
|
||||
<option value="title_desc" <?php selected(isset($_GET['sort_order']) ? $_GET['sort_order'] : 'date_desc', 'title_desc'); ?>>Title (Z-A)</option>
|
||||
</select>
|
||||
</div>
|
||||
if (!empty($terms) && !empty($taxonomy_obj)): ?>
|
||||
<div class="custom-dropdown">
|
||||
<button type="button" class="dropdown-toggle"><?php echo esc_html($taxonomy_obj->labels->singular_name); ?></button>
|
||||
<div class="dropdown-menu">
|
||||
<?php foreach ($terms as $term): ?>
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo esc_attr($taxonomy); ?>[]" value="<?php echo esc_attr($term->slug); ?>" <?php echo (isset($_POST[$taxonomy]) && in_array($term->slug, (array) $_POST[$taxonomy])) ? 'checked' : ''; ?>>
|
||||
<?php echo esc_html($term->name); ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php if (!defined('ABSPATH')) { exit; } ?>
|
||||
|
||||
<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 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>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php endif; ?>
|
||||
|
||||
<input class="full-width" type="text" name="search" placeholder="Search resources...">
|
||||
|
||||
<button class="btn btn-primary" type="submit">Search</button>
|
||||
</form>
|
||||
@@ -16,37 +16,36 @@ if (!empty($_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))
|
||||
];
|
||||
}
|
||||
// Get selected taxonomies from admin settings
|
||||
$selectedTaxonomies = get_option('content_filter_taxonomies', []);
|
||||
|
||||
// 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))
|
||||
];
|
||||
// Handle dynamic taxonomy filters
|
||||
foreach ($selectedTaxonomies as $taxonomy) {
|
||||
if (!empty($_POST[$taxonomy])) {
|
||||
$selectedTerms = is_array($_POST[$taxonomy]) ? $_POST[$taxonomy] : [$_POST[$taxonomy]];
|
||||
$taxonomyObj = get_taxonomy($taxonomy);
|
||||
|
||||
if ($taxonomyObj) {
|
||||
$filters[] = [
|
||||
'type' => $taxonomy,
|
||||
'value' => esc_html(implode(',', $selectedTerms)),
|
||||
'label' => '<strong>' . esc_html($taxonomyObj->labels->singular_name) . ':</strong> ' . esc_html(implode(', ', $selectedTerms))
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display filters as HTML
|
||||
$filter_html = '';
|
||||
$filterHtml = '';
|
||||
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']) . '">'
|
||||
$filterHtml .= '<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';
|
||||
$filterHtml = 'None';
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -57,19 +56,19 @@ if (!empty($filters)) {
|
||||
<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>
|
||||
<label for="sortOrder">Sort by:</label>
|
||||
<select id="sortOrder">
|
||||
<option value="date_desc" <?php selected(isset($_GET['sortOrder']) ? $_GET['sortOrder'] : '', 'date_desc'); ?>>Newest First</option>
|
||||
<option value="date_asc" <?php selected(isset($_GET['sortOrder']) ? $_GET['sortOrder'] : '', 'date_asc'); ?>>Oldest First</option>
|
||||
<option value="title_asc" <?php selected(isset($_GET['sortOrder']) ? $_GET['sortOrder'] : '', 'title_asc'); ?>>Title (A-Z)</option>
|
||||
<option value="title_desc" <?php selected(isset($_GET['sortOrder']) ? $_GET['sortOrder'] : '', '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>
|
||||
<span id="applied-filters"><?php echo $filterHtml; ?></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) { exit; } // Prevent direct access
|
||||
|
||||
if (!empty($resources)) :
|
||||
foreach ($resources as $resource) :
|
||||
$postID = $resource->ID;
|
||||
$postTitle = get_the_title($postID);
|
||||
$postLink = get_permalink($postID);
|
||||
?>
|
||||
<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>
|
||||
<?php endif; ?>
|
||||
@@ -1,34 +1,38 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) { exit; } // Prevent direct access
|
||||
|
||||
// Define dynamic post type and taxonomy
|
||||
// $postType = isset($postType) ? $postType : 'post'; // Default to 'post' if not set
|
||||
// $taxonomy = isset($taxonomy) ? $taxonomy : 'category'; // Default to 'category' if not set
|
||||
|
||||
if (!empty($resources)) :
|
||||
foreach ($resources as $resource) :
|
||||
$postID = $resource->ID;
|
||||
$postTitle = get_the_title($postID);
|
||||
$postLink = get_permalink($postID);
|
||||
$terms = get_the_terms($postID, 'resource_type');
|
||||
$postType = get_post_type($postID);
|
||||
$terms = get_the_terms($postID, $taxonomy);
|
||||
|
||||
$img = has_post_thumbnail($postID) ? get_the_post_thumbnail_url($postID, 'full') : get_field('admin', 'option')['imgDefault']['url'] ?? '';
|
||||
?>
|
||||
<div class="px-4 sm:px-0">
|
||||
<?php if (has_post_thumbnail($postID)) : ?>
|
||||
<div class="block bg-[#F3F3F3] h-[32rem]">
|
||||
<a href="<?php echo esc_url($postLink); ?>">
|
||||
<img src="<?php echo esc_url(get_the_post_thumbnail_url($postID)); ?>" alt="<?php echo esc_attr($postTitle); ?>"
|
||||
class="flex justify-center items-center w-full h-full object-contain">
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="block mb-4">
|
||||
<a href="<?php echo esc_url($postLink); ?>">
|
||||
<img src="<?php echo esc_url($img); ?>" alt="<?php echo esc_attr($postTitle); ?>" class="flex justify-center items-center w-full h-full object-contain">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<p class="text-sm font-thin uppercase">
|
||||
<?php echo $terms ? esc_html(strtolower($terms[0]->name)) : ''; ?>
|
||||
<p class="text-sm font-thin uppercase px-2 mb-1!">
|
||||
Post Type: <?php echo $postType; ?>
|
||||
</p>
|
||||
|
||||
<div class="flex">
|
||||
<div class="flex px-2">
|
||||
<div>
|
||||
<h3 class="text-lg"><a class="" href="<?php echo esc_url($postLink); ?>"><?php echo esc_html($postTitle); ?></a></h3>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center ml-auto pr-4">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 ml-2">
|
||||
<div class="flex ml-auto mt-1">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5 ml-2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
|
||||
</svg>
|
||||
</div>
|
||||
@@ -36,5 +40,5 @@ if (!empty($resources)) :
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<p>No resources found.</p>
|
||||
<p>No results.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
border: 1px solid #ccc;
|
||||
border-right: none;
|
||||
font-size: 1rem;
|
||||
padding: .5rem;
|
||||
padding: 1rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
|
||||
#resource-results {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
gap: 1.5rem;
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 20px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.pagination ul {
|
||||
Reference in New Issue
Block a user