I have a client who’s site will be making heavy use of custom post types to configure their site. But I’m between a rock and a hard place for their requested home page.

In reality, the home page will be a stack of specific “pages” within WordPress. Basically, there will be pages for: Intro, Blog, About Us, Portfolio, and Contact Us. They’ll all be stacked on top of one another so you can scroll from one page to another.

My first instinct was to just use a page (called Home) and embed a shortcode that accepts page slugs and outputs the proper order (i.e. [pageOrder]intro, blog, about-us, portfolio, contact-us[/pageOrder]). The page would use a custom page template to lay things out, control the loop, and add navigation to the left side of the page. But that all seems klunky.

My ideal solution would be to create a custom post type (called Stack) that allows the end user to position the pages with drag-drop and have the CPT take care of layout and navigation and such.

The problem with my ideal solution is settings. WordPress allows you to select a page for the default home page of the site. But it’s tied to a post type of page, and I’m not sure where to hook in to modify that so that users could also select a Stack as the default home page.

So, where do I hook in to in order to add a CPT to the dropdown of available pages for the default home page?

5

Thanks to @toscho for the useful answer, but it felt a bit hackish to me, so I poked around a bit and figured out I could add a filter instead:

function wpa18013_add_pages_to_dropdown( $pages, $r ){
    if('page_on_front' == $r['name']){
        $args = array(
            'post_type' => 'stack'
        );
        $stacks = get_posts($args);
        $pages = array_merge($pages, $stacks);
    }

    return $pages;
}
add_filter( 'get_pages', 'wpa18013_add_pages_to_dropdown', 10, 2 );

Update

After adding the above code I was, indeed, able to use a custom post type as the home page, but WordPress would redirect the permalinks because it wasn’t a “page” post type. So http://localhost/test would redirect to http://localhost/test/stacks/home-stack, which wasn’t what I wanted.

Adding this action, though, fixed that and queries my custom post type along with pages for the home page:

function enable_front_page_stacks( $query ){
    if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
        $query->query_vars['post_type'] = array( 'page', 'stack' );
}
add_action( 'pre_get_posts', 'enable_front_page_stacks' );

Leave a Reply

Your email address will not be published. Required fields are marked *