Support » Themes and Templates » Get list of template file candidates that will be tried for current request

  • Resolved Rulatir

    (@rulatir)


    I understand that when WordPress is about to require a template file, it checks several files in order, e.g. page-$id.php, page-$slug.php, page.php, index.php (for a page request), each in the child theme first, then in the parent theme.

    Question: is there an API to get the list of candidates that will be checked for the current query?

    I want to use this list to generate a similar list to use with locate_template() for small blocks that are in separate files. For example, if I have a menu, and the request is a page request, I want these files tried: parts/menu-page-$id.php, parts/menu-page-$slug.php, parts/menu-page.php, parts/menu.php. And I want this to mimic the behavior of WordPress template hierarchy for all kinds of requests (page/archive/category/taxonomy/single, etc.) but without me reimplementing the whole logic.

    Possible?

Viewing 1 replies (of 1 total)
  • By looking at the code I can tell that this is unfortunately completely impossible. I will submit patch to fix this shortcoming. Too bad it won’t make it into 3.5.

Viewing 1 replies (of 1 total)
  • The topic ‘Get list of template file candidates that will be tried for current request’ is closed to new replies.