WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get list of template file candidates that will be tried for current request (2 posts)

  1. Rulatir
    Member
    Posted 1 year ago #

    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?

  2. Rulatir
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.