This theme has several classes that will help you create a wordpress theme. You can find them in the folder libs. We will describe some of them
1.0.0
You need Node JS node js
You need grunt installed globally:
$ npm install -g grunt-cli
Bower installed. Bower is a command line utility.
$ npm install -g bower
$ npm install
$ bower install
$ grunt
watch js, css, less:
$ grunt watch
distrubution task (compress less, minify css, uglify, minify js)
$ grunt prod
This class should have all your Ajax code
In the construct of this class add, the wordpress ajax action and the method that you will using
add_action( 'wp_ajax_contacts', array($this, 'contacts' ) );
add_action( 'wp_ajax_nopriv_contacts', array($this, 'contacts' ) );
Then create the method
public function contacts()
{
//our code
die();
}
This class should have all the wordpress hooks that you will create or use.
- The Actions should be in the method custom_hooks_actions_noadmin or custom_hooks_actions.
- The Filters should be in the method custom_hooks_filters_noadmin or custom_hooks_filters.
- There is already the method pre_get_posts for the action pre_get_posts
public function custom_hooks_actions()
{
add_action('wploop', array($this, 'wploop') , 10 , 2);
}
public function wploop($content , $args)
{
//our code
}
This class should have all the wordpress shortcodes that you will create.
Add in the $shortcodes array, in the init method of this class, all the shortcode themes
public static function init() {
$shortcodes = array(
'youtube' => __CLASS__ . '::youtube'
);
}
Then create the static method where will be the shortcode code
public static function youtube($atts, $content=null) {
our code
}
This class should have all the theme code. Basically should be the controller of your theme. This Class have some methods that we will talk later
Configuration files are used to store any kind of configuration needed for the theme. They are plain PHP files, stored in the config/ folder, which return an associative array
return array(
'setting' => 'value',
'options' => array(
'foo' => 'bar',
),
);
If the above configuration file was called myconf.php, you could access it using:
$conf = Helper::load_config('myconf');
echo $conf['setting'] ;
Is a configuration file where you could add some options that your theme will need. In this moment you can create only four type of inputs ( text , chekbox , select, radio)
return array(
'fields' => array(
array(
'type' => 'text',
'id' => 'teste_id',
'title' => 'Teste Id',
'args' => array(
'type' => 'text',
'name' => 'teste_id',
'desc' => 'descrição teste Id',
'class' => 'css_class'
)
),
array(
'type' => 'text',
'id' => 'teste_id2',
'title' => 'Teste Id2',
'args' => array(
'name' => 'teste_id2',
'desc' => 'descrição teste Id2',
'class' => 'css_class'
)
),
array(
'type' => 'checkbox',
'id' => 'responsive',
'title' => 'Teste responsive',
'args' => array(
'value' => '1',
'name' => 'responsive',
'desc' => 'descrição responsive',
'class' => 'css_class'
)
),
array(
'type' => 'select',
'id' => 'cores',
'title' => 'cores',
'args' => array(
'options' => array(
'azul' => 'cor azul',
'amarelo' => 'cor amarelo',
'verde' => 'cor verde',
),
'name' => 'cores',
'desc' => 'descrição cores',
'class' => 'cores'
)
),
array(
'type' => 'radio',
'id' => 'maintenance',
'title' => 'maintenance',
'args' => array(
'options' => array('yes'=> 'Sim', 'no' =>'Não'),
'name' => 'maintenance',
'desc' => 'descrição maintenance',
'class' => 'maintenance'
)
),
)
)
Is a configuration file (menu.php) where you create all your theme menus
return array(
array('primary' => 'Primary Navigation'),
array('footer' => 'Footer Navigation')
);
Is a configuration file (site.php) where you set all your theme configuration
return array(
'multilang' => false,
'translate_uri' => false,
'default_lang' => 'pt',
'protocol' => 'http://',
);
If your theme is multilang, there is also configuration file (lang.php).
return array(
'name' => 'namespace',
'folder' => '/lang'
);
The folder is where your files.po will be and the name is the namespace of _e("string" , namespace). Important in the configuration file site.php the option multilang should be true
Is a file (customPostTypes.php) in the config folder where will be all your content Post types. Use this site http://generatewp.com/post-type/ to help you to create your content Post types
Supports flashdata, or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").
Add Flashdata:
Helper::set_flashdata("name" , value);
Get Flashdata:
Helper::get_flashdata("name");
Delete all Flashdata:
Helper::unset_all_flashdata();
A view is a simply php file that could be include in any place of our code, without any logic programming. This files are in the views folder
Create a view and set is variables
$view = View::factory();
$view->set('variable1', $data);
$view->set('variable2', $data2);
echo $view->render('viewfilename');
In this theme you dont need to always call the header and the footer, you only need to set what is the view that should be render
global $site;
$site->set_content('page' , array('template' =>'PAGE'));
In the set_content method the first parameter is the view you want to call , and the second parameter is a array of the view variables.
You could do that also through the Site Class this way.
Site Class code :
public function page()
{
$this->view->set('template', "PAGE");
$content = $this->view->render('page');
$this->content($content);
}
In the template file
<?php
global $site;
$site->page();
?>
The views header , head , footer , and main (the content view) are in views/template/
- VIEWS (view folder path)
- LIBS (libs folder path)
- CONFIG (config folder path)
- THEMEURL
- THEMEPATH
- data_header , a array where you can store data, that could access in the view template/header.php. In the __construct of class Site, set this properties, doing this away, the data that you define is the same in all site
//In Site.php
function __construct()
{
parent::__construct();
$this->data_header = array( "teste" => "data header");
}
//In template/header.php
<?php if(isset($data_header['teste'])) echo $data_header['teste'] ?>
- data_footer , a array where you can store data, that could access in the view template/footer.php. In the __construct of class Site, set this properties, doing this away, the data that you define is the same in all site
//In Site.php
function __construct()
{
parent::__construct();
$this->data_footer = array( "teste" => "data footer");
}
In template/footer.php
//template/footer.php
<?php if(isset($data_footer['teste'])) echo $data_footer['teste'] ?>
- data_main , a array where you can store data, that could access in the view template/main.php. In the __construct of class Site, set this properties, doing this away, the data that you define is the same in all site
//In Site.php
function __construct()
{
parent::__construct();
$this->data_main = array( "teste" => "data main");
}
//In template/main.php
<?php if(isset($data_main['teste'])) echo $data_main['teste'] ?>
- set_data_header($data_header = array()), you set the $data_header just in the specific method , and could only access to this data when, you call this method
//In Site.php
public function index()
{
$data_header = array( "teste" => "data header");
$this->set_data_header($data_header);
$content = $this->view->render('index');
$this->content($content);
}
- set_data_footer($data_footer= array()), you set the $data_footer just in the specific method , and could only access to this data when, you call this method
//In Site.php
public function index()
{
$data_footer = array( "teste" => "data footer");
$this->set_data_footer($data_footer);
$content = $this->view->render('index');
$this->content($content);
}
- set_data_main($data_main= array()), you set the $data_main just in the specific method , and could only access to this data when, you call this method
//In Site.php
public function index()
{
$data_main = array( "teste" => "data main");
$this->set_data_main($data_footer);
$content = $this->view->render('index');
$this->content($content);
}
-
set_data_header($data_header = array()), you set the $data_header just in a specific method , and could only access to this data when you call this method
In Site.php
public function index()
{
$data_header = array( "teste" => "data header");
$this->set_data_header($data_header);
$content = $this->view->render('index');
$this->content($content);
}
- set_view($view , $data = array())
$site->set_view($view , $data )
- get_view($view , $data = array())
$view = $site->get_view($view , $data )
- pagination($num_pages)
echo $site->pagination(10)
This class have, like her name says, some helpers:
- current_uri()
HELPER::current_uri()
- current_url()
HELPER::current_url()
- get_protocol()
HELPER::get_protocol()
- redirect($location, $status=302)
HELPER::redirect($location, $status)
- getSiteTitle()
HELPER::getSiteTitle()
- siteInfo()
HELPER::siteInfo()
- link_select($url , $class)
HELPER::link_select("http://www.xpto.com" , "active")