WordPress Custom generator

In this documentation you can see, how you can create dynamic slide generators from your own code. To understand how our generator codes are built up, check out  this documentation.

To have a customized generator, you will need to create a new plugin. To do that, you will need a folder with a customized name, like this one:

And it should have a php file inside it with the same name:

It should have a code like this:

 * Plugin Name: Custom Smart Slider 3 Generator

add_action('smartslider3_generator', 'custom_generator');

function custom_generator(){
	class N2SSPluginGeneratorCustom extends N2SliderGeneratorPluginAbstract {

		protected $name = 'custom';
		protected $path;

		function __construct() {
			$this->path = plugin_dir_path( __FILE__ );			

		public function getLabel() {
			return 'Custom';

		public function isInstalled() {
			return N2Filesystem::existsFolder($this->path);

		protected function loadSources() {
			$dir = opendir($this->path . 'sources');
			while ($file = readdir($dir)) {
				if ($file == '.' || $file == '..') {
				$filename = substr($file, 0, -4);
				$class    = 'N2GeneratorCustom' . $filename;
				new $class($this, $filename, $filename);

		public function getPath() {
			return $this->path;
    N2SSGeneratorFactory::addGenerator(new N2SSPluginGeneratorCustom);

You could use exactly that code, but if you want to understand what is going on, the main structure of that file is the same, as ours, for example at the Post generator:

Just you need to put the entire code into a function to be able to call pass it through with the add_action.

The next file is dynamic.png:

This is the image, which is used in the admin area.

Then the file you actually need is this one:
\wp-content\plugins\smartslidergenerator\sources\[unique generator name].php

The  [unique generator name].php has to be a unique name for your generator, for example mygenerator.php.

This file have to contain a similar code:

N2Loader::import('libraries.slider.generator.abstract', 'smartslider');

class N2GeneratorCustomMyGenerator extends N2GeneratorAbstract {

    protected $layout = 'article';

    public function renderFields($form) {

        $filter = new N2Tab($form, 'posts', n2_('Filter'));
        $group = new N2ElementGroup($filter, 'some_values_id', 'Some values');
        new N2ElementTextarea($group, 'values', n2_('Values separated by comma'), 'these,are,default,values', array(
            'fieldStyle' => 'width:150px;height:150px;'
	protected function _getData($count, $startIndex) {
		$values = explode(',', $this->data->get('values', 'these,are,default,values'));
		$data = array();
		for($i=0; $i<count($values); $i++){
			$data[$i]['value_variable_name'] = $values[$i];
		return $data;

I used  N2GeneratorCustomMyGenerator for my example, but if you followed my smartslidergenerator.php code, it has to be N2GeneratorCustom[your unique generator name] , so use the same unique name in this class name, what you used for the filename. To understand the codes of my example, check out our generator code documentation.

You can have any number of [your unique generator name].php files, if you want to have more generators.

You can activate your Plugin now and it will be used by our code!

This should be enough for a custom generator, but you have one more option to make your generator more complex.

In the admin area you are able to create options, like if you take a look at the  post generator's options, you will see "Categories". Those categories are asked down from the database by this file:

You could create an elements folder:

To have similar, maybe the same exact code in your folder:

This way you could ask down multiple datas from the database and the user of the admin area would be able to select for example from a dropdown list or a multiselection and you could process the result. If you take a look into the post generator's file:

you can see how it works, that inside the renderFields function you are creating the option:

new N2ElementWordPressCategories($group, 'postscategory', n2_('Categories'), 0);

where the $group is just a main container and the N2ElementWordPressCategories will be the name, which is inside your 'elements' file too. The 'postscategory' is the identifier, there is a name and a default value. Inside the _getData function you will be able to use the identifier to get the value:

$categories = $this->data->get('postscategory');

and you will be able to use that for any PHP codes.