PHP code example of piassi / solidpress

1. Go to this page and download the library: Download piassi/solidpress 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/ */

    

piassi / solidpress example snippets


use SolidPress\Core\Theme;
use SolidPress\Core\WPTemplate;

// Composer autoload
lds
if (function_exists('acf_add_local_field_group')) {
	$registrable_namespaces[] = 'FieldsGroup';
	$registrable_namespaces[] = 'Options';
}

// Set core registrables
$registrable_namespaces = array_merge($registrable_namespaces, [
	'Taxonomies',
	'PostTypes',
	'Hooks',
]);

// Setup a theme instance for SolidPress
global $theme_class;
$theme_class = new Theme([
	'template_engine' => new WPTemplate(),
	'namespace' => 'App',
	'base_folder' => 'src',
	'registrable_namespaces' => $registrable_namespaces,
	'theme_name' => 'solidpress-theme',
	'css_dist_path' => get_template_directory_uri() . '/dist/%s.css', // %s will be replaced with page bundle css file.
	'js_dist_path' => get_template_directory_uri() . '/dist/%s.js', // %s will be replaced with page bundle js file.
]);

// Filepath: src/PostTypes/Products.php

namespace App\PostTypes;

use SolidPress\Core\PostType;

class Products extends PostType{
	public function __construct()
	{
		$this->post_type = "product";

		$labels = [
			"name" => "Products",
			"singular_name" => "Product",
			"menu_name" => "Products",
			"all_items" => "All Products",
			"add_new" => "Add new",
			"add_new_item" => "Add new product",
			"edit_item" => "Edit product",
			"new_item" => "New product",
			"view_item" => "View proct",
			"insert_into_item" => "Insert in product",
			"view_items" => "View products",
			"search_items" => "Search for products",
			"not_found" => "No products found",
			"not_found_in_trash" => "No products found in trash"
		];

		$this->args = [
			"label"               => "Products",
			"labels"              => $labels,
			"description"         => "",
			"public"              => true,
			"publicly_queryable"  => false,
			"show_ui"             => true,
			"show_in_rest"        => false,
			"rest_base"           => "",
			"has_archive"         => false,
			"show_in_menu"        => true,
			"exclude_from_search" => true,
			"capability_type"     => "post",
			"map_meta_cap"        => true,
			"hierarchical"        => false,
			"menu_position"       => 8,
			'rewrite'             => array("slug" => $this->post_type, "with_front" => false),
			'query_var'           => false,
			"supports"            => array("title", "editor", "revisions", "excerpt"),
			"menu_icon"           => 'dashicons-book-alt',
			"taxonomies"          => []
		];
	}
}


// Filepath: src/FieldsGroup/Product.php

namespace App\FieldsGroup;

use SolidPress\Core\FieldGroup;
use SolidPress\Core\PostType;
use SolidPress\Fields;

class Product extends FieldGroup{
	public function __construct() {
		// Set fields
		$this->set_fields([
			'product_detailts_tab' => new Fields\Tab('Product Details'),
			'value' => new Fields\Number('Value'),
			'subtitle' => new Fields\Text('Subtitle', [
				// You can pass an acf options array as the second argument
				'wrapper' => [
					'width' => 70
				]
			]),
			'gallery_thumbnail' => new Fields\Image('Gallery Thumbnail', [
				'wrapper' => [
					'width' => 30
				]
			])
		]);

		// Set arguments
		$this->args = [
			'key' => 'product-fields',
			'title' => 'Product Fields',
			'location' => [
				[
					// Pages, Taxonomies, OptionsPages, and PostTypes
					// classes have static methods for acf conditionals.
					PostType::is_equal_to('product'),
				],
			]
		];
	}
}