Timber\Site
Timber\Site
gives you access to information you need about your site. In Multisite setups, you can get info on other sites in your network.
PHP
$other_site_id = 2;
$context = Timber::context( [
'other_site' => new Timber\Site( $other_site_id ),
] );
Timber::render('index.twig', $context);
Twig
My site is called {{site.name}}, another site on my network is {{other_site.name}}
HTML
My site is called Jared's blog, another site on my network is Upstatement.com
Overview #
This class extends Timber\Core
This class implements Timber\CoreInterface
Properties #
Name | Type | Description |
---|---|---|
$admin_email | string | The admin email address set in the WP admin panel |
$blogname | string | |
$charset | string | |
$description | string | |
$home_url | string | |
$id | int | the ID of a site in multisite |
$language | string | the language setting ex: en-US |
$multisite | bool | true if multisite, false if plain ole' WordPress |
$name | string | |
$pingback_url | string | for people who like trackback spam |
$rdf | string | |
$site_url | string | |
$siteurl | string | |
$theme | \Timber\Theme | |
$title | string | |
$url | string |
Methods #
Name | Return Type | Summary/Returns |
---|---|---|
__call() | mixed | Magic method dispatcher for site option fields, for convenience in Twig views. Returns: The value of the option field named $field if truthy, false otherwise. |
__construct() | Constructs a Timber\Site object | |
__get() | mixed | Get the value for a site option. Returns: The option value. |
icon() | null or \Timber\Image | |
link() | string | Returns the link to the site's home. |
Get the value for a site option. | ||
option() | mixed | Get the value for a site option. Returns: The option value. |
Class Methods #
__call() #
Magic method dispatcher for site option fields, for convenience in Twig views.
Called when explicitly invoking non-existent methods on the Site object. This method is not meant to be called directly.
link https://secure.php.net/manual/en/language.oop5.overloading.php#object.call
__call( string $option, array $arguments )
Returns: mixed
The value of the option field named $field
if truthy, false
otherwise.
Name | Type | Description |
---|---|---|
$option | string | The name of the method being called. |
$arguments | array | Enumerated array containing the parameters passed to the function. Not used. |
The following example will dynamically dispatch the magic __call() method with an argument of "users_can_register" #}
Twig
{% if site.users_can_register %}
{# Show a notification and link to the register form #}
{% endif %}
---
### \_\_construct()
Constructs a Timber\Site object
`__construct( string|int $site_name_or_id = null )`
<div class="table-responsive">
| Name | Type | Description |
| --- | --- | --- |
| $site_name_or_id | `string` or `int` | |
</div>
**PHP**
```php
//multisite setup
$site = new Timber\Site(1);
$site_two = new Timber\Site("My Cool Site");
//non-multisite
$site = new Timber\Site();
__get() #
Get the value for a site option.
__get( string $option )
Returns: mixed
The option value.
Name | Type | Description |
---|---|---|
$option | string | The name of the option to get the value for. |
Twig
Published on: {{ post.date|date(site.date_format) }}
icon() #
Returns: null|\Timber\Image
link() #
Returns the link to the site's home.
Returns: string
Twig
<a href="{{ site.link }}" title="Home">
<img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
</a>
HTML
<a href="https://example.org" title="Home">
<img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
</a>
meta() #
Get the value for a site option.
DEPRECATED since 2.0.0, use {{ site.option }}
instead
meta( mixed $option )
option() #
Get the value for a site option.
option( string $option )
Returns: mixed
The option value.
Name | Type | Description |
---|---|---|
$option | string | The name of the option to get the value for. |
Twig
Published on: {{ post.date|date(site.option('date_format')) }}