Templates
In HivePress, templates are implemented as PHP classes that define arrays of blocks. With blocks, it’s easy to re-use and customize specific layout parts without affecting the whole template. You can always check the available templates in the includes/templates
subdirectory of HivePress or its extensions.
Creating templates
If you are developing a custom HivePress extension, you may need to create a new template. To do this, create a new class-{template-name}.php
file (use lowercase letters, numbers, and hyphens only) in the includes/templates
extension subdirectory and HivePress will load it automatically.
Then, define the template PHP class. The class name should be based on the file name but with underscores instead of hyphens and no lowercase restriction (e.g. Foo_Bar
class for the class-foo-bar.php
file). Pick a name that is unique enough to avoid conflicts with other HivePress templates.
The code example above implements a template based on the Page_Wide
template and adds the Listing Search Form along with the Listings block that displays 9 recent listings in 3 columns. These blocks are added to the page_content
block inherited from the Page_Wide
template.
In the same way, you can create custom templates for your HivePress extension.
Customizing templates
You can customize any of the existing templates using hooks. For example, the code below changes the number of columns on the Listings page to 3.
Similarly, you can customize any template in HivePress or its extensions.
Last updated