Skip to main content


public function init_page( int $pid, bool $standalone )

This method is intended to be used when building layouts directly inside theme template files, as opposed to building layout components in the theme layout class' build_components() method and setting the component order in determine_attributes().

This method sets up the layout class similiar to how the build_page() method does, but with a few key differences:

  • init_page() does not call the determine_attributes() method. Insteaded, minimal attributes are set.
  • init_page() does not call the build_layout() method, as it is assumed that you will be building the layout manually. That being said, reusable components can still be build by using the build_component() method.
  • init_page() does set $attr["is_front"] to true if the post ID passed to the method is the ID of the front page.
  • init_page() does query and store post meta and theme options in the $meta and $opts properties.
  • init_page() can only be used for single post templates (not archives)


  • $pid
    (int) (required) The post ID that you would like to load data for

  • $standalone
    (bool) (optional) By default, the build_component(), get_header_markup(), and get_footer_markup() methods will only return markup from $this->html. Any added scripts or modals will be returned with get_footer_markup() when it is called. If you do no intend to call get_footer_markup(), pass the $standalone argument for init_page() as true. When set to true, build_component(), get_header_markup(), and get_footer_markup() will return merged output containing the contents of $this->html, $this->scripts, and $this->modals, resetting the contents of each every time one of the methods is called.
    Default: 'false'


Below is an example of a page template built using init_page():

Template Name: My Custom Page Template
$layout = new MethodThemeLayout;
$layout->init_page( $post->ID );
echo $layout->get_header_markup();
echo $layout->build_component( 'page-header' );
if ( have_posts() ) {
while ( have_posts() ) {
echo '
<div class="method-page-content">
<div class="container-fluid ' . method_get_class( 'full_width_container' ) . '">
<div class="row justify-content-center">
<div class="' . method_get_class( 'full_width_outer_col' ) . '">
echo '
} // end while
} // end if
echo $layout->build_component( 'call-to-action' );
echo $layout->get_footer_markup();