wp-lemon Docs
WP_Lemon_Site
WP_Lemon_Site
WP_Lemon_Site
You will be able to retrieve this information from the context in your twig files or in your php files under the global $context variable.
Here we will add an example
PHP
my_method( 'example', false );
Overview
Methods
Name | Return Type | Summary/Returns |
---|---|---|
add_site_information() | Static method to add site information from wherever you want. | |
extend_site_information() | array | This is the main method that is overridden by the child-site class. Returns: $context The updated Timber context. |
get_archive_page() | array or false | Get archive information of singular item. Returns: Contains ['id', 'title', 'url/link', 'status'] |
get_site_information() | mixed | Get specific site information. Returns: $value The value retrieved from the site information. |
get_special_page() | array or false | Get special page information. Returns: Contains ['id', 'title', 'url/link'] or false if key does not exist. |
is_post_type() | Check if the current post type is one of the given post types. |
Class Methods
add_site_information()
Static method to add site information from wherever you want.
This method is internally used to check if the key already exists before adding it.
since 4.0
add_site_information( string $key, mixed $value )
Name | Type | Description |
---|---|---|
$key | string | The key under which this context can be accessed. |
$value | mixed | The value to be stored. |
Example usage:
PHP
protected function my_custom_method() { $my_custom_value = [];
self::add_site_information('my-key', $my_custom_value);}
extend_site_information()
This is the main method that is overridden by the child-site class.
Everything returned from this method will be added to the site information if the key does not exist yet.
since 3.36.0
Returns: array
$context The updated Timber context.
Example usage from within the child-site class:
PHP
function extend_site_information(): array{ return [ //'key' => and use your custom child method here ];}
get_archive_page()
Get archive information of singular item.
When a page is set as the archive page for a post type, this method will return the title and url of that page.
get_archive_page( string|null $post_type = null )
Returns: array|false
Contains ['id', 'title', 'url/link', 'status']
Name | Type | Description |
---|---|---|
$post_type | string or null | Use this post type instead of current post type. |
Example usage:
PHP
public function block_context($context): array { $news_archive = WP_Lemon_Child_Site::get_archive_page('news');
}
get_site_information()
Get specific site information.
since 4.0
get_site_information( string $key )
Returns: mixed
$value The value retrieved from the site information.
Name | Type | Description |
---|---|---|
$key | string | The key under which this context can be accessed. |
get_special_page()
Get special page information.
Use in conjunction with the special pages filter to setup special pages and then retrieve them via this method.
link https://studio-lemon.github.io/wp-lemon-docs/extend/special-pages
since 5.36.0
get_special_page( string $key )
Returns: array|false
Contains ['id', 'title', 'url/link'] or false if key does not exist.
Name | Type | Description |
---|---|---|
$key | string | The key of the special page. |
Example usage:
PHP
public function block_context($context): array { $contact_page = WP_Lemon_Child_Site::get_special_page('contact');}
is_post_type()
Check if the current post type is one of the given post types.
since 4.0
is_post_type( string|array $post_type )
Name | Type | Description |
---|---|---|
$post_type | string or array | The post type to check against. |
Example usage:
PHP
if (self::is_post_type(['example', 'example2'])) {// do something}
Edit this page on GitHub