GeniXCMS

Widget Class

categoryAPI edit_calendar31 Mar 2026

Aspect-Based Widget & Sidebar Class


The Widget class is the primary engine for rendering dynamic, reusable content blocks (Widgets) across various theme locations. It provides a standardized framework for both core system widgets (e.g., Recent Posts, Tag Cloud) and custom module-driven components, ensuring a consistent visual architecture throughout your platform.


⚡ Active Rendering Logic

GeniXCMS widgets are location-aware. They are retrieved and rendered based on their assigned region in the admin dashboard.

Widget::show(string $location)

The primary entry point for theme integration.

  • Process: Fetches all active records assigned to the specified $location (e.g., sidebar, footer_1), sorts them by their manual priority, and returns the aggregated HTML.
  • Implementation: Typically called within a theme's sidebar.php or footer.php.
{* In your theme's sidebar.tpl *}
<aside class="col-md-4 main-sidebar">
    {Widget::show('sidebar')|noescape}
</aside>

Widget::addLocation(string $id, string $name)

(Since 2.0.0) Registers a custom destination slot for widgets programmatically. This enables theme developers to expose specific template locations to the admin dashboard.

  • Implementation: Typically called within your theme's function.php or a module's initialization.
// Register new widget locations inside your theme
Widget::addLocation('header_top', 'Top Header Area');
Widget::addLocation('sidebar_left', 'Sidebar Left (Secondary)');

Widget::getLocations()

Retrieves all registered widget locations. Returns an associative array [id => name]. This method automatically invokes the widget_locations hook, allowing plugins to intercept and modify the available regions dynamically:

Hooks::attach('widget_locations', function($locations) {
    $locations['custom_slot'] = 'My Custom Slot';
    return $locations;
});

🏗️ Supported Content Types

The Widget engine automatically resolves various content sources into standardized HTML modules:

Type Description
Recent Posts Automatically fetches the 5 most recent articles with thumbnails.
Recent Comments Lists newest reader interactions for social proof.
Tag Cloud Injects a frequency-weighted list of site-wide tags.
Static Content Renders raw HTML or text provided via the admin editor.
Module Hook Dynamically triggers a specified Hook to pull data from a third-party module.

🎨 Professional UI Blueprint

Every widget is wrapped in a standardized, Bootstrap-compliant container to ensure design consistency across all themes.

<div class="widget-box mb-4" id="widget-12">
    <div class="widget-header">
        <h3 class="widget-title h5 fw-bold m-0 text-uppercase">
            <i class="bi bi-star-fill me-2"></i> Widget Title
        </h3>
    </div>
    <div class="widget-body">
        <!-- Widget Dynamic Content ... -->
    </div>
</div>

🏹 Management Workflow

  • Drag & Drop: Reorder widgets in the dashboard under Appearance > Widgets.
  • Location Mapping: Assign widgets to specific theme slots (e.g., Header, Main Sidebar, Post Footer).
  • Configuration: Edit the internal title and content (plain text or HTML) for each instance.

lightbulb
TipCustom Module Widgets: To create a widget for your module, use the Custom Module type and specify a unique hook name. Then, in your module's function.php, use Hooks::attach('your_hook', 'your_render_function') to inject your own HTML.

priority_high
ImportantStyling Consistency: Ensure your theme's CSS targets the .widget-box, .widget-header, and .widget-body classes to maintain a premium, unified aesthetic for the entire sidebar subsystem.

See Also

  • Hooks Class — How module-driven widgets are registered.
  • Theme Class — Integrating widget locations into your templates.
  • Widgets Guide — Managing your site's sidebars in the dashboard.