diff --git a/README.md b/README.md index de026b7..b541617 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Add one of the following shortcodes to your page or post content where you want ## Configuration The plugin is designed to work out of the box with minimal configuration. However, you can customize the following: -- **Templates**: Override the default templates and styles by placing your custom versions in your theme's `resource-filter` directory. +- **Templates**: Override the default templates and styles by placing your custom versions in your theme's `resource-filter` directory. You will need to add `"./resource-filter/**/*.{php,vue,js,cjs}",` to the `content` object in your `tailwind-config.js` file to compile the custom styles. - **Template Files**: - `filter-form.php` - Main form template - `filter-homepage.php` - Secondary form template for the homepage or other uses diff --git a/assets/cf-banner.webp b/assets/cf-banner.webp new file mode 100644 index 0000000..17ba0c4 Binary files /dev/null and b/assets/cf-banner.webp differ diff --git a/assets/cf-icon.webp b/assets/cf-icon.webp new file mode 100644 index 0000000..02e20da Binary files /dev/null and b/assets/cf-icon.webp differ diff --git a/resource-filter.php b/resource-filter.php index 10521a9..4be3525 100644 --- a/resource-filter.php +++ b/resource-filter.php @@ -4,7 +4,7 @@ * Plugin URI: https://github.com/Vincent-Design-Inc/resource-filter * Update URI: https://github.com/Vincent-Design-Inc/resource-filter * Description: Adds filtering for the content typed by various taxonomies. - * Version: 1.5.1 + * Version: 1.5.2 * Author: Keith Solomon */ @@ -188,38 +188,75 @@ class ContentFilterPlugin { $resTotal = $query->found_posts; // Default total resource count - // Determine which form template to load - if ($atts['type'] === 'homepage') { - $homepage_taxonomy = get_option('content_filter_homepage_taxonomy', ''); - - if (!empty($homepage_taxonomy) && taxonomy_exists($homepage_taxonomy)) { - $GLOBALS['homepage_taxonomy'] = $homepage_taxonomy; // Pass the taxonomy globally for the template - $attTmpl = 'filter-homepage.php'; - } else { - echo '
Error: No valid taxonomy configured for the homepage filter.
'; - return ob_get_clean(); - } - } else { - $attTmpl = 'filter-form.php'; + $attTmpl = $this->getTemplate($atts['type']); + if (!$attTmpl) { + return ob_get_clean(); } $resForm = rfGetTemplate($attTmpl); $summary = rfGetTemplate('filter-summary.php'); - if ($resForm) { - include_once $resForm; - } else { - echo 'Error: Form template not found.
'; + $this->includeTemplate($resForm, 'Form template not found.'); + if ($atts['type'] === 'default') { + $this->includeTemplate($summary, 'Summary template not found.'); + $this->renderResourceResults($query); } - if ($atts['type'] === 'default') { - if ($summary) { - include_once $summary; - } else { - echo 'Error: Summary template not found.
'; - } - ?> + return ob_get_clean(); + } + /** Retrieves the template file for the given filter type. + * + * @param string $type The type of filter. Accepts 'default' or 'homepage'. + * @return string|false The path to the template file or false if the homepage filter has no configured taxonomy. + * + * @since 1.0.0 + */ + 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'; + } else { + echo 'Error: No valid taxonomy configured for the homepage filter.
'; + return false; + } + } else { + return 'filter-form.php'; + } + } + + /** Includes a template file. + * + * If the template file is found, it is included once. Otherwise, an error message is displayed. + * + * @param string $template The path to the template file. + * @param string $errorMessage The error message to display if the template file is not found. + * + * @since 1.0.0 + */ + private function includeTemplate($template, $errorMessage) { + if ($template) { + include_once $template; + } else { + echo 'Error: ' . $errorMessage . '
'; + } + } + + /** Renders the resource results. + * + * If the request method is POST, this directly renders the filtered results. + * Otherwise, it loads all resources initially. + * + * This function also handles pagination for the resource results. + * + * @param \WP_Query $query The WP_Query object for the resource results. + * + * @since 1.0.0 + */ + private function renderResourceResults($query) { + ?>