Single page theme that uses pages for the content

How-to simplify your life

I’d go a fairly simpler route:

  • Add a “main/parent” page
  • Apply your template there
  • Add “child” pages to this main page
  • Alter the query to include them

Code example as plugin for a quick test

Here’s an (untested) plugin that modifies the query args to not only reduce it to a single query, but modify the main query, so no performance increase has to be taken.

Explanation

I’m not sure how you could retrieve the parent post (current) ID inside the function. I guess you have to set it manually. Anyway: Try it with get_queried_object_id() (which will likely not work) or see if you could retrieve it from the $query object. You could also attach a second filter to post_clauses and just change the arguments in this filter (where get_queried_object_id() should already be present – or not).

The nice thing that this function does is to attach the orderby value as menu_order, so you can make use of what the page post type supports by default. Imo you should always make as much use of what core offers as possible.

<?php
/** Plugin Name: (#70317) »kaiser« Fetch all child posts */
/**
 * Calls the child pages
 * 
 * @param  object $query
 * @return object $query
 */
function wpse70317_pre_get_posts( $query )
{
    if (
        ! $query->is_home()
        OR ! $query->is_front_page()
        OR ! $query->is_main_query()
        )
    {
        return $query;
    }

    $query->set( 'post_type', 'page' );
    $query->set( 'post_status', 'inherit' );

    // Allow the menu order (meta value) to be used
    // ... and start with 0 and count up
    $query->set( 'order', 'ASC' );
    $query->set( 'orderby', 'menu_order' );

    // Change this to your parent posts ID
    $query->set( 'post_parent', 1 );

    return $query;
}
add_action( 'pre_get_posts', 'wpse70317_pre_get_posts' );

Leave a Comment