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.
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_archive_page() | bool | Check if the current page is an archive page for a specific post type. Returns: True if the current page is an archive page for the specified post type, false otherwise. |
| is_post_type() | Check if the current post type is one of the given post types. | |
| is_special_page() | bool | Check if the current page is a special page. Returns: True if the current page is a special page, false otherwise. |
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.
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_archive_page()
Check if the current page is an archive page for a specific post type.
since 5.48.1
is_archive_page( string $post_type = null )
Returns: bool True if the current page is an archive page for the specified post type, false otherwise.
| Name | Type | Description |
|---|---|---|
| $post_type | string or null | The post type to check against. If null, uses current post type. |
Example usage:
PHP
if (WP_Lemon_Child_Site::is_archive_page('news')) {
// Do something on the news archive page.
echo 'This is the news archive page';
}
// Check if current page is archive for current post type
if (WP_Lemon_Child_Site::is_archive_page()) {
// Do something on any archive page
}
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
}
is_special_page()
Check if the current page is a special page.
since 5.36.0
is_special_page( string $key, bool $or_is_child_of = false )
Returns: bool True if the current page is a special page, false otherwise.
| Name | Type | Description |
|---|---|---|
| $key | string | The key of the special page. |
| $or_is_child_of | bool | If true, it will also check if the current page is a child of the special page. |
Example usage:
PHP
if (!WP_Lemon_Child_Site::is_special_page('contact')) {
return;
}
// Do something on the contact page.
Timber::render('partials/contact-form.twig', $context);