Skip to content

Requiring scopes

Andrew Tolochka edited this page Jul 11, 2016 · 1 revision

Very often WordPress pages have common layouts and are based on the same set of data, however each of them requires some more specific data. Classy provides an easy way on how the data can be structured and then loaded and extended:

First of all you need to require your default page scope like this:

$default_data = ClassyScope::require_scope('page');

This code will require scope that is located in theme/scope/page.php. This way you can require any scope. Make sure that the directories are presented with dotes instead of slashes: 'page.about', 'category.books'.

The output will look as an array_merge of our default page scope and new data:

$data = array_merge( $default_data, array( 'foo' => 'Bar' ) );

Clone this wiki locally