Wordpress - Menus, widgets, sidebars


Adding menus

The process is the same as it would be under standard WordPress, but instead of adding to the function.php file, you add the code to your __wpload() magic method in default.ctl.php:

register_nav_menu( 'primary', __( 'Primary Menu', 'mozajik-light' ) );

You can then place the menu tag in your HTML code as such:

{% wp_nav_menu 'primary' 'nav' '2' %}

Details on available tags and their parameters are available here.

Unfortunately there is no current way to customize the HTML generated for menus. You need to style it in your CSS file.

Adding widgets

You can register widgets using OFW’s custom register_widget function (see docs). You can also use WordPress’s built-in method if you need more control over admin settings and such.

Here’s how to do it with OFW:

$this->zajlib->wordpress->register_widget(array(
		'name' => 'Name of the widget',
		'id'   => 'a_unique_id_for_the_widget',
		'reroute' => '/path/to/controller/'
	));

Any widgets created with $this->zajlib->wordpress->register_widget() will be added to the OFW Custom Widgets widget where you can select it from the dropdown to add it.

Adding sidebars

Sidebars are customizable areas on the page where you can add widgets via the WordPress admin. Sidebars can be anywhere in the page where you add the wp_sidebar tag (see below).

As with menus, add the init code to your __wpload() magic method in default.ctl.php:

$this->zajlib->wordpress->register_sidebar(array(
    'name' => 'Name of sidebar',
    'id'   => 'unique-sidebar-id',
    'description'   => 'Description of sidebar',
));

You can now use the proper template tag to display the widget / sidebar in the correct place:

{% wp_sidebar 'unique-sidebar-id' %}

Once you have widgets and you have sidebars you can add widgets to each sidebar via the WordPress admin GUI by going to WP Admin / Appearance / Widgets.

Outlast Web & Mobile Development (c) 2019 | Privacy Policy |