API – Modules – Introduction

Available on: Newsmag V1.8+, Newspaper V5+
The td_api_module api call allows you to add or modify a module. The modules are used on loops or on blocks, they come in various designs, for example in frontend module 1 looks like this:

td_api_module_1_frontend
Newsmag – Module 1

 

The blocks are predefined to use certain blocks but on loops like Article List or on the default wordpress templates (ex. category, tag, archive, blog pages). You can use the settings which appear on Theme Panel -> Templates or on Article List setup section (appears on page editing section if you use a Homepage – with article list page template) to change the default module which is module 1. If you use the API to add a new module it will appear on backend like this:

td_api_module_77_backend

The theme modules are registered in td_config.php, the code looks like this:

td_api_module::add('td_module_1',
    array(
        'file' => td_global::$get_template_directory . '/includes/modules/td_module_1.php',
        'text' => 'Module 1',
        'img' => td_global::$get_template_directory_uri . '/images/panel/modules/td_module_1.png',
        'used_on_blocks' => array('td_block_3'),
        'excerpt_title' => 12,
        'excerpt_content' => '',
        'enabled_on_more_articles_box' => true,
        'enabled_on_loops' => true,
        'uses_columns' => true,
        'category_label' => true,
        'class' => 'td_module_wrap td-animation-stack',     // custom css module class
    )
);

Parameters:

$id (string) (required)

  • the module id – if you add a new module the id has to be different from the ones used on the other modules which are registered in theme, if you plan to modify one of the existing module the id has to match with the one you’re planing to modify.

$params_array (array) (required)

  • an array which contains the parameters of the module:
Key name
Type
Description
file string the path of the module template file
text string the module title, appears in Theme Panel and on Article List settings area
img string the path for the icon used to represent the module
used_on_blocks array the blocks on which this module is used
excerpt_title integer title excerpt length
excerpt_content integer content excerpt length
enabled_on_more_articles_box boolean show the module in the more articles box in panel -> post settings -> more articles box
enabled_on_loops boolean show the module in panel on loops
uses_columns boolean enable/disable column use on this block, if it’s disabled it will display only one module on each row
category_label boolean show the module in panel -> block_settings -> category label
class string classes added on the module wrapper