Templates

Plugin contains simple template loader. Idea is to bring default templates into plugins which could be simply overwritten from theme. All default files are located inside plugin’s templates folder. Implementation can be found in class-horizon-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.

  • archive-listing.php
  • content-listing.php
  • single-listing.php
  • taxonomy-listing.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 listings in rows. We will use custom query to fetch all listings in database.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
query_posts( array(
    'post_type'        => Horizon_Custom_Post_Type::get_listing_post_types(),
    'posts_per_page'   => -1
) );

if ( have_posts() ):
    while( have_posts ): the_post();
        include Horizon_Template_Loader::locate( 'listings/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.

1
2
3
4
5
6
7
8
// This will return the template path
Horizon_Template_Loader::locate( 'listings/row' );

// Output the content
include Horizon_Template_Loader::locate( 'listings/row' );

// In $row we have template content
$row = Horizon_Template_Loader::load( 'listings/row' );