Nopio Alm Filter

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

ArgumentTypeDescriptionRequired
namestringUnique identifier for the filter (used as ALM shortcode ID).Yes
wrapper_classstringAdditional CSS classes for the wrapper.No
mobile_selectboolEnables mobile dropdown select functionality.No
toggle_mobileboolEnables mobile toggle button functionality.No
show_allboolEnables "Show All" option for filters.No
show_all_taxonomyarrayList of taxonomies to enable "Show All" button.No
override_button_textassociative arrayOverrides 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 name is 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.