PHP code example of potterywp / potter

1. Go to this page and download the library: Download potterywp/potter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

potterywp / potter example snippets


   

use Potter\Potter;

$features = Potter::features();

// $features->addMenu($location, $description);
$features->addMenu('main', 'Menu Principal');

// $features->addThemeSupport($feature, $arguments = array());
$features->addThemeSupport('post-thumbnails');
$features->addThemeSupport('post-formats');

// $features->addPostTypeSupport($post_type, $feature)
$features->addPostTypeSupport('page', 'excerpt');

// $features->addImageSize($name, $width = 0, $height = 0, $crop = false);
$features->addImageSize('thumb-home', 300, 300, true);
$features->addImageSize('thumb-page', 248, 888, true);
$features->addImageSize('thumb-contact', 460, 400, false);

// $features->addCss($handle, $src = false, $deps = array(), $ver = null, $media = 'all');
$features->addCss('gfonts', 'http://fonts.googleapis.com/css?family=Rosario:400,700');
$features->addCss('main', 'assets/pub/css/main.css');

// $features->addJs($handle, $src, $deps = array(), $ver = null, $in_footer = false);
// $features->addJsToHead($handle, $src, $deps = array(), $ver = null);
// $features->addJsToFooter($handle, $src, $deps = array(), $ver = null);

$features->addJsToHead('modernizr', 'assets/pub/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js');
$features->addJsToFooter('app', 'assets/pub/js/app.js');

// $features->setJqueryCDNSupport($version, $fallback = null, $migrate = null, $in_footer = false);
$features->setJqueryCDNSupport('2.1.1', 'assets/pub/js/vendor/jquery-2.1.1.min.js', 'assets/pub/js/vendor/jquery-migrate-1.2.1.min.js');

// $features->setGoogleAnalytcsID($id);
$features->setGoogleAnalytcsID('A1-XXXXXX');

// $features->setLoginLogo($logo, $style = array());
$features->setLoginLogo('assets/pub/imgs/login-logo.png', array('width'=>'150px'));


 use Potter\Theme\Options;

 class ThemeOptions extends Options
 {
    protected $page_title = 'Opções do Tema';
    protected $menu_title = 'Opções do Tema';
    protected $settings_id = 'my_theme_options_id';

    public function doRegister()
    {
    }
 }

 class ThemeOptions extends Options
 {
    protected $page_title = 'Theme Options';
    protected $menu_title = 'Theme Options';
    protected $settings_id = 'theme_options';
    protected $header_logo = null;
    protected $header_version_text = null;
    protected $header_logo_link = null;
    protected $show_new_layout = false;
    protected $show_docs = false;
    protected $show_pages = false;
    protected $options_capability = 'edit_theme_options';

    protected $contextual_help
        = array(
            'content' => array(),
            'sidebar' => ''
        );


 public function doRegister()
 {
    // Primeiro você cria a seção
    $this->addSection('general', 'Geral')
        // depois você adcionar as opções, que são automaticamente inseridas na devida seção
        ->addUpload('logo', 'Logo')
        ->addText('header_slogan', 'Header Slogan');
    
    $this->addSection('another_section', 'Another')
        ->addTextArea('text_impact', 'Text impact')
        ->addPageSelect('my_page_id', 'Select Page');
    
    
    // Você não é obrigado a encadear os metodos
    $this->addSection('more_section', 'GoT');
    $this->addCustomPostTypeSelect('my_got_id','Select GoT', 'Desc of select', 'got');
    $this->addCategorySelect('my_cat_id','Select GoT', 'Desc of select', 'got');
    // As as opções são anexadas automaticamente a última seção configurada.
    
 }


$option_name = OPT::get('option_name', 'default_value');

OPT::_get('option_name', 'default_value'); // echo OPT::get('option_name', 'default_value');

$option = OPT::get_nl2br('option_name', 'default_value'); // $option =  nl2br(OPT::get('option_name', 'default_value'));

OPT::_get_nl2br('option_name', 'default_value') // echo nl2br(OPT::get('option_name', 'default_value'));




use Potter\Post\Type;

class SliderType extends Type
{
	protected $supports = array('title', 'thumbnail');
	protected $public = false;
	protected $show_ui = true;
	public $icon = 'picture-o';
}



use Potter\Post\Type;

class SliderType extends Type
{
    public $type = 'carrocel'; // força o post type da classe
    protected $taxonomies = array();
    protected $labels = array();
    protected $capabilities = array();
    protected $args = array();
    protected $supports = array();
    public $icon = 'dashicons-admin-post';
    protected $capability_type = 'page';
    protected $public;
    protected $show_ui;
    protected $description;
    protected $route;
    protected $queryArgs = array();

    protected $meta_boxes = array();
}

protected $meta_boxes
        = array(
            'metabox-id' => array(
                'title' => 'Dados do slider',
                'fields' => array(
                    array(
                        'name' => 'link',
                        'id' => 'link',
                        'type' => 'text',
                        'clone' => false,
                    ),
                    array(
                        'name' => 'Target',
                        'id' => 'target',
                        'type' => 'select',
                        'options' => array(
                            '_new',
                            '_self',
                        )
                    )
                )
            )
        );

// Retorna um objeto WP_Query
$sliders = \Potter\Potter::model('slider')->all(); // passe como parametro o nome do model/post type que você criou

// Nada muda no seu código
if($query->have_posts()):
    while($query->have_posts()): $query->the_post()
        /// 
    endwhile;
endif;


// Retorna um objeto Potter/Post/ModelQuery
$slidersQuery = \Potter\Potter::model('slider'); // passe como parametro o nome do model/post type que você criou

// Retorna um objeto WP_Query
$slidersQuery->perPage(15)->order('author')->exclude(99)->exe();

// Retorna um objeto WP_Query
$slidersQuery->perPage(15)->exe();
$slidersQuery->exe($args = array()); // Passe parametros extras diretamente para o WP_Query
$slidersQuery->get(5, $args = array()) // Uma quantidade limitada de resultados

// Retorna um objeto WP_Query
$slidersQuery->perPage(5)->byParent(9) // Páginas filhas do ID 9
$slidersQuery->perPage(5)->exclude(get_the_ID())->byParent(9) // Páginas filhas do ID 9, menos a página atual