Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7899711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:46:38+00:00 2026-06-03T08:46:38+00:00

How do you make page templates load based on a page’s entire url not

  • 0

How do you make page templates load based on a page’s entire url not just their slug?

Page templates load either page-{slug}.php or page-{id}.php.

I really want it to load page-{parent-slug}_{slug}.php.

So the url /hello/world would look for the template page-hello_world.php.

This should be recursive so the longer the page url the longer template filename.

There is no template_redirect documentation in the API.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:46:40+00:00Added an answer on June 3, 2026 at 8:46 am

    This is what I came up with. It works great and added it to the functions.php file in the theme’s folder:

    function hierarchical_template() {
        global $post;       
        $permalink_array =
            array_filter(explode('/',str_replace(get_site_url(),'',get_permalink($post->ID))));     
        $template_redirect = false;     
        while ( count( $permalink_array ) ) {           
            $template = 'page-' . implode( '_', $permalink_array ) . '.php';            
            if(file_exists(TEMPLATEPATH . '/' . $template)){
                include (TEMPLATEPATH . '/' . $template);
                exit;               
            }           
            array_shift($permalink_array);
        }
    }
    
    add_action('template_redirect', 'hierarchical_template');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you make a page-based application (using UIPageViewController) in xcode 4.3.1 and iOS5 you
i have this image in the background: http://yoursdproperty.com/templates/pjo_joomlaforall/images/bgr.png of this page: http://yoursdproperty.com/index.php?option=com_jumi&fileid=8&Itemid=34 how do
I'm using Wordpress page templates to pull posts with certain categories into their own
How to make page turn animation like the Stanza app ? Earlier i was
I am using a stored procedure to make page-navigation when I view a list
I have to make a page that look like painting below, but: field 1
trying to make a page which will recursively call a function until a limit
I'm trying to make a page for a photo story - it's meant to
I am trying to make web page which would display two other webpages side
I'm trying to make a page with some Points in it. E.g: Point1 Point2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.