Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to mimic the page hierarchy rules of WP. I'm checking for the existence of certain files, then requiring them if they exist -- in the same order as I understand the hierarchy rules. Here's a snippet:

if (is_author() === TRUE)
    if (file_exists('_author-NICENAME.php') === TRUE)
        require '_author-NICENAME.php';
    elseif (file_exists('_author-ID.php') === TRUE)
        require '_author-ID.php';
    elseif (file_exists('_author.php') === TRUE)
        require '_author.php';
    elseif (file_exists('_archive.php') === TRUE)
        require '_archive.php';
        // missing _author-NICENAME.php, _author-ID.php, _author.php, or _archive.php
        require '_index.php';

The parts of the file name that are in ALL CAPS are dynamic data, right? How do I get an author's "NICENAME" or "ID", etc.? I need this also for POSTTYPE, MIMETYPE, SUBTYPE, category SLUG, category ID, CUSTOM page, page SLUG, page ID, single POSTTYPE, tag SLUG, tag ID, TAXONOMY, taxonomy TERM, etc.


Since I am trying to determine which files to load (in an attempt to mimic the hierarchy rules), I don't think I can be inside The Loop. I think this limits the functions available to me in order to get the dynamic data.

share|improve this question
Had you explored documentation? In current form this question asks someone else to go and do rather menial function lookups for you. – Rarst May 15 '13 at 20:20
I have -- and continue to do so. I'm new to WP. And although I see functions like, it seems to accept a parameter which is unfamiliar to me. – snoopy76 May 15 '13 at 20:27
Assuming that parameter is the post id, then I can get it using the_ID() function, but that must be in "The Loop". Seems like I am getting deeper in the rabbit hole. Hoping someone here will give a simpler solution. – snoopy76 May 15 '13 at 20:37
Sorry to disappoint, but you are precisely in the right rabbit hole. :) – Rarst May 15 '13 at 20:39
Oh boy. Does that mean that my snippet of code is supposed to be in a loop? Are files like author.php supposed to be just the markup for one iteration of the loop? – snoopy76 May 15 '13 at 20:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.