0

For a one page website, I have modified the homepage to index all pages instead of posts. For some of the pages I want to create a custom template (like page-slug.php). But, these template only get loaded when on a singular page, not on index/archive pages.

A solution to this problem would be very much appreciated. THX!

3
  • Have you looked at codex.wordpress.org/Function_Reference/get_template_part ?
    – kraftner
    Commented Jul 15, 2014 at 11:26
  • Yes, this would be the second best solution. I'm still hoping there is a 'non-programming' solution by simply using the template hierarchy of WordPress.
    – puyol5
    Commented Jul 15, 2014 at 12:15
  • Well the template hierarchy doesn't target segments of pages, just whole page templates. Can you add the template of your homepage anyway, maybe then someone can come up with something smart ;)
    – kraftner
    Commented Jul 15, 2014 at 12:34

1 Answer 1

0
add_filter( 'template_include', 'wpsites_home_page_template', 99 );

function wpsites_home_page_template( $template ) {

    if ( is_singular( 'page' )  ) {
        $new_template = locate_template( array( 'single_page-template.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }

    return $template;
}

You should be able to tweak something like this to get it to do what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.