Skip to content

Instantly share code, notes, and snippets.

@joelalejandro
Last active December 16, 2015 14:59
Show Gist options
  • Save joelalejandro/5453172 to your computer and use it in GitHub Desktop.
Save joelalejandro/5453172 to your computer and use it in GitHub Desktop.
<?php
require "Vendor/compage/src/Compage.php";
require "MyWeb.php";
<?php
use Compage\Essentials\Context;
Context::get(__THEME__)->get("IndexController")->instantiate()->render();
<?php
namespace Eurofrits\Theme\Controllers;
use Compage\Component\Controller;
class IndexController extends Controller {
public function __construct($theme) {
parent::__construct($theme, "Index");
$this->hook(function($txt) {
return str_replace("<br />\r\n<br />", "</p><p>", nl2br($txt));
})->toFilter("the_content");
}
public function render() {
$this->getPluggable()->get("HomePageController")->instantiate()->render();
}
}
<?php
namespace MyWeb\Theme;
use Compage\Theme\Theme;
use Compage\Component\ComponentType;
class MyWebTheme extends Theme {
public function __construct($base_file) {
parent::__construct($base_file);
$this->setFullyQualifiedName(__NAMESPACE__)
->setName("MyWebTheme")
->registerLocale("es_ES")
->registerLocale("en_US")
->registerLocale("it_IT")
->registerLocale("pt_PT")
->registerLocale("fr_FR")
->addFeature("post-thumbnails", array("products"))
->addFeature("shortcode-in-widgets")
->addStylesheet("css/bootstrap.min.css", "screen")
->addStylesheet("css/bootstrap-responsive.min.css", "screen")
->addStylesheet("css/main.css", "screen")
->addScript("js/vendor/jquery-1.9.0.min.js")
->addScript("js/bootstrap.min.js")
->addScript("js/main.js")
->addImage("img/logo.png")
->addImage("img/1.jpg")
->addImage("img/2.jpg")
->addImage("img/3.jpg")
->addImage("img/4.jpg")
->addMenu("myweb-header-menu", "Menú principal", function($menu) {
wp_nav_menu(array(
"theme_location" => $menu["id"],
"container" => "nav",
"menu_class" => "nav"
));
})
->addMenu("myweb-company-menu", "Menú de la página de la compañía", function($menu) {
wp_nav_menu(array(
"theme_location" => $menu["id"],
"menu_class" => "nav nav-pills"
));
})
->onInitialize(function($theme) {
remove_filter("the_content", "wpautop");
})
->initialize();
}
}
Theme::activate("MyWebTheme", __FILE__);
<?php
namespace MyWeb\Theme\CustomTaxonomies;
use Compage\Extensions\CustomTaxonomy\CustomTaxonomy;
class ProductCategoriesCustomTaxonomy extends CustomTaxonomy {
public function __construct($pluggable) {
parent::__construct($pluggable, "ProductCategoriesCustomTaxonomy");
$slug = __("productos", __THEME__);
$this->setLabels(array(
'name' => __('Categorías de producto', __THEME__),
'singular_name' => __('Categoría de producto', __THEME__),
'search_items' => __('Buscar categorías de producto', __THEME__),
'all_items' => __('Todas', __THEME__),
'parent_item' => __('Categoría de producto superior', __THEME__),
'parent_item_colon' => __('Categoría de producto superior', __THEME__) . ":",
'edit_item' => __('Modificar categoría de producto', __THEME__),
'update_item' => __('Guardar categoría de producto', __THEME__),
'add_new_item' => __('Agregar categoría de producto', __THEME__),
'new_item_name' => __('Nombre de la categoría de producto', __THEME__),
'menu_name' => __('Categoría de producto', __THEME__)
));
$this->hierarchical(true);
$this->showsUI(true);
$this->showsAdminColumn(true);
$this->hasQueryVar(true);
$this->setRewrite(array("slug" => $slug));
$this->addMetaField("category_color", array("type" => "text", "name" => __("Color", __THEME__)));
$this->addMetaField("category_thumb", array("type" => "text", "name" => __("Imagen de categoría", __THEME__)));
$this->addMetaField("category_invisible", array("type" => "checkbox", "name" => __("Invisible", __THEME__)));
}
}
<?php
namespace MyWeb\Theme\CustomPostTypes;
use Compage\Extensions\CustomPostType\CustomPostType;
class ProductsCustomPostType extends CustomPostType {
public function __construct($pluggable) {
parent::__construct($pluggable, "ProductsCustomPostType");
$slug = __("productos", __THEME__);
$this->setLabels(array(
'name' => __('Productos', __THEME__),
'singular_name' => __('Producto', __THEME__),
'add_new' => __('Agregar', __THEME__),
'add_new_item' => __('Agregar producto', __THEME__),
'edit' => __('Editar', __THEME__),
'edit_item' => __('Editar producto', __THEME__),
'new_item' => __('Nuevo producto', __THEME__),
'view' => __('Ver', __THEME__),
'view_item' => __('Ver producto', __THEME__),
'search_items' => __('Buscar productos', __THEME__),
'not_found' => __('No hay productos', __THEME__),
'not_found_in_trash' => __('No hay productos en la Papelera', __THEME__),
'parent' => __('Producto padre', __THEME__)
));
$this->isPublic(true);
$this->setMenuPosition(4);
$this->supports("title")->supports("thumbnail")->supports("editor");
$this->hasArchive(true);
$this->usesTaxonomy("ProductCategories");
$this->setRewrite(array(
"slug" => "$slug/%category%",
"hierarchical" => true
));
$this->addMetaField("energetic_value", array("name" => __("Valor energético", __THEME__), "type" => "text"));
$this->addMetaField("proteins", array("name" => __("Proteínas", __THEME__), "type" => "text"));
$this->addMetaField("carbohydrates", array("name" => __("Carbohidratos", __THEME__), "type" => "text"));
$this->addMetaField("fat", array("name" => __("Grasas", __THEME__), "type" => "text"));
/** Próximamente esto va a poder hacerse a través de la API de Compage, sin
* recurrir a las acciones directas de Wordpress **/
add_action("do_meta_boxes", function() {
remove_meta_box("postimagediv", "products", "side");
add_meta_box("postimagediv", __("Imagen del producto", __THEME__), "post_thumbnail_meta_box", "products", "normal", "high");
});
add_filter("admin_post_thumbnail_html", function($content) {
$instructions = "<p><i>" . __('Haga clic en el enlace de arriba para agregar la imagen del producto', __THEME__) . ".</i></p>";
if (stripos($content, $instructions) === false) $content .= $instructions;
return str_replace(__("Set featured image", __THEME__), __("Agregar imagen", __THEME__), $content);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment