Blog

Singleton entity, contains essential blog informations

Properties & methods

PropertyDescriptionType

ID

Site ID

int

archive_link(post_type)

Post type archive link

string

archive_title(post_type)

Post type archive title

string

body_class

The class names for the body element

string

breadcrumb

Default navigational aid

array

charset

Displays the “Encoding for pages and feeds”

string

debug

Symfony debug mode

bool

description

Displays the “Tagline”

string

domain

Blog current domain

string

environment

Symfony environment

string

home_link(path)

URL for the current site

string

info(name)

Information about the current site

string

language

Language code for the current site ( ex : en-US )

string

language_attributes

HTML lang attribute ( ex : lang="en-US" )

string

languages

Return all available languages

array

locale

Locale code for the current site ( ex : en )

string

login_link(redirect)

Retrieves the login URL

string

maintenance_mode

Maintenance mode

bool

menu

object

meta

Get site meta

mixed

network_home_link(path)

Retrieves the home URL for the current network.

string

option(name)

Retrieves an option value based on an option name

string

options

Return option helper

object

paged

Current pagination offset for archive

int

pagination

Default archive pagination

array

posts(args, order, limit)

Perform a WP_Query, return PostCollection

object

posts_per_page

Default posts per page value

int

privacy_policy_link

The URL to the privacy policy page

string

privacy_policy_title

The title of the privacy policy page

string

queried_object

Return WP_Query queried object

mixed

search_link(query)

Retrieves the permalink for a search

string

terms(args, order, limit)

Perform a WP_Term_Query, return TermCollection

object

title

Page title for all areas of blog

string

user

Current connected user entity

object

users(args, order, limit)

Perform a WP_User_Query, return UserCollection

object

version

Version set in project composer.json

string

is_admin

Current user is an administrator

bool

is_archive

The query is for an existing archive page

array

is_customize_preview

The site is being previewed in the Customizer

bool

is_front_page

The query is for the front page of the site.

bool

is_single

The query is for an existing single post

bool

is_tax

The query is for an existing custom taxonomy archive page

bool

Examples

Usage of blog properties in layout.html.twig

<!DOCTYPE html>
<html lang="{{ blog.locale }}">
<head>
    <meta charset="{{ blog.charset }}">
    <meta http-equiv="Content-Type" content="text/html; charset={{ blog.charset }}" />
    <title>{{ blog.title|raw }}</title>
    {{ wp_head() }}
    {% if blog.custom_fields.matomo.domain|default %}
    <script>
        var _paq = window._paq = window._paq || [];
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function() {
            var u="https://{{ blog.custom_fields.matomo.domain }}/";
            _paq.push(['setTrackerUrl', u+'matomo.php']);
            _paq.push(['setSiteId', '1']);
            var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
            g.async=true; g.src='//cdn.matomo.cloud/{{ blog.custom_fields.matomo.domain }}/matomo.js'; s.parentNode.insertBefore(g,s);
        })();
    </script>
    {% endif %}
</head>
<body class="{{ blog.body_class }}">
...

Display breadcrumb

<ul>
  {% for page in blog.breadcrumb %}
    <li>
      {% if not loop.last %}
        <a href="{{ page.link }}">{{ page.title }}</a>
      {% else %}
        {{ page.title }}
      {% endif %}
    </li>
  {% endfor %}
</ul>

Display custom field

Get specific ACF Option page value see https://www.advancedcustomfields.com/resources/options-page/

{{ blog.custom_fields.my_option }}

Display meta

Metadata for a site see https://developer.wordpress.org/reference/functions/get_site_meta/

{{ blog.meta.my_meta }}

Display blog info

Information about the current site see https://developer.wordpress.org/reference/functions/get_bloginfo/

{{ blog.info.name }}

Display language selector

Return languages, using WPML or MSLS

{% if blog.languages %}
  <ul>
    {% for language in blog.languages %}
        <li>
          <a class="{{ language.active ? 'active' : 'inactive' }}" href="{{ language.url }}">{{ language.language_code }}</a>
        </li>
    {% endfor %}
  </ul>
{% endif %}

Display menu

Return navigation entity

{% if blog.menu.footer %}
<ul>
    {% for item in blog.menu.footer.items %}
      <li>
        <a href="{{ item.link }}" class="{{ item.class|default }}" target="{{ item.target|default('_self') }}" rel="{% if item.target|default == '_blank' %}noreferrer noopener{% endif %}">{{ item.title|raw }}</a>
      </li>
    {% endfor %}
</ul>
{% endif %}

Display option

Retrieves an option value based on an option name. see https://developer.wordpress.org/reference/functions/get_option/

{{ blog.option.my_option }}

Query posts : $criteria=[], array $orderBy = null, $limit = null, $offset = null

Perform a WP_Query, return PostCollection see https://developer.wordpress.org/reference/classes/wp_query/ Please note that post query should be done in a controller

{% set posts = blog.posts({post_type:'guide', tax_query: [{taxonomy:'type', field:'slug', terms:'test'}]}, null, 6 ) %}
{% for post in posts %}
     <a href="{{ post.link }}">{{ post.title }}</a>
{% endfor %}

Query terms : $criteria=[], array $orderBy = null, $limit = null, $offset = null

Perform a WP_Term_Query, return TermCollection see https://developer.wordpress.org/reference/classes/WP_Term_Query/__construct/ Please note that term query should be done in a controller

{% for type in blog.terms('type') %}
    <label>
        <input type="radio" value="{{ type.slug }}" name="type"><span>{{ type.title }}</span>
    </label>
{% endfor %}

Query users : $criteria=[], array $orderBy = null, $limit = null, $offset = null

Perform a WP_User_Query, return UserCollection see https://developer.wordpress.org/reference/classes/wp_user_query/ Please note that user query should be done in a controller

{% set users = blog.users({role:'subscriber'}, null, 6 ) %}
{% for user in users %}
     <a href="{{ user.link }}">{{ user.display_name }}</a>
{% endfor %}

Last updated