NopioAlmFilter Class Documentation
This documentation provides an overview, implementation details, and usage examples for the NopioAlmFilter class.
Class Overview
The NopioAlmFilter class manages AJAX Load More (ALM) filter functionality in WordPress. It encapsulates filter rendering, responsive behaviors for mobile, and taxonomy-specific configurations.
Key Features
- Rendering AJAX filters via shortcode.
- Mobile responsiveness with toggle and select options.
- "Show All" functionality for taxonomies with customizable button text.
Initialization and Usage
Creating an Instance
To instantiate a NopioAlmFilter object, provide an associative array of configuration options:
$nopio_alm_filter = new NopioAlmFilter([
'wrapper_class' => '',
'name' => 'case_study',
'mobile_select' => true,
'show_all' => true,
'show_all_taxonomy' => ['case-study-category'],
'override_button_text' => [
'case-study-category' => 'All Case Studies'
]
]);Configuration Arguments
| Argument | Type | Description | Required |
|---|---|---|---|
name | string | Unique identifier for the filter (used as ALM shortcode ID). | Yes |
wrapper_class | string | Additional CSS classes for the wrapper. | No |
mobile_select | bool | Enables mobile dropdown select functionality. | No |
toggle_mobile | bool | Enables mobile toggle button functionality. | No |
show_all | bool | Enables "Show All" option for filters. | No |
show_all_taxonomy | array | List of taxonomies to enable "Show All" button. | No |
override_button_text | associative array | Overrides default "Show All" button text per taxonomy. | No |
Methods
get_filter_args()
Returns the array of filter configuration arguments.
shortcode_preview()
Outputs the shortcode preview for the AJAX Load More filter:
$nopio_alm_filter->shortcode_preview();
// Output: ajax_load_more_filters id="case_study" target="case_study"render()
Renders the entire filter interface, including mobile responsiveness and ALM shortcode:
$nopio_alm_filter->render();render_search()
Renders a search component associated with the filter:
$nopio_alm_filter->render_search();Mobile Responsiveness
Mobile Select
When mobile_select is enabled, the wrapper gains the class js-alm-select, turning filter options into a mobile-friendly dropdown.
Mobile Toggle
When toggle_mobile is enabled, the filters become collapsible on mobile devices.
"Show All" Functionality
The "Show All" button resets taxonomy-based filters. It can be customized per taxonomy using the override_button_text parameter:
'show_all' => true,
'show_all_taxonomy' => ['case-study-category'],
'override_button_text' => [
'case-study-category' => 'All Case Studies'
]This adds a "Show All" button labeled "All Case Studies" before the filters for the case-study-category taxonomy.
Error Handling
The constructor validates the presence of essential parameters:
- Throws an exception if
nameis not provided.
// Throws Exception
new NopioAlmFilter([]);Ensure proper argument configuration to avoid runtime exceptions.
Extending the Class
The NopioAlmFilter class can be extended to add further customizations. Developers can override or add methods to modify filter rendering or handling logic.
This documentation aims to provide clarity and efficiency for developers interacting with AJAX Load More filters using the NopioAlmFilter class.