Templates

Plugin contains simple template loader. Idea is to bring default templates into theme which could be simply overwritten from theme. All default files are located inside plugin’s templates folder. Implementation can be found in class-realia-template-loader.php.

Loader is used to define some default templates for single and archive templates. Custom post types defined by theme which are public have default fallbacks in plugin templates folder.

  • single-property.php
  • single-agency.php
  • single-agent.php
  • archive-property.php
  • archive-agency.php
  • archive-agent.php

Loading Hierarchy

Template loader has its hierarchy for loading the templates. First of all it checks child theme, if it is used. Then it looks into theme folder and at the end loads default template from plugin folder.

Loader Usages

Below you can see an example how it is possible to output list of properties in rows. We will use custom query to fetch all properties in database.

query_posts( array(
    'post_type'         => 'property',
    'posts_per_page'    => -1
) );

if ( have_posts() ):
    while( have_posts ): the_post();
        include Realia_Template_Loader::locate( 'properties/row' );
    endwhile;
endif;

If you want to save the output into variable, use load() method instead of locate(). Method is using locate(), but it implements ob_start() functionality to return template content as variable.

// This will return the template path
Realia_Template_Loader::locate( 'properties/row' );

// Output the content
include Realia_Template_Loader::locate( 'properties/row' );

// In $row we have template content
$row = Realia_Template_Loader::load( 'properties/row' );