WordPress.org

Ready to get started?Download WordPress

Forums

Is there a way to output debug info for the Template Hierarchy? (10 posts)

  1. mrtaylor
    Member
    Posted 2 years ago #

    I want to display a list of theme files used to display any page I'm on. I need to see what combinations wordpress is using. I thinks I deleted some code by accident and it falling back to something else.. but I'm not sure what.
    I'm looking for something that is kinda like showing the database queries and load time.

  2. ChristiNi
    Member
    Posted 2 years ago #

    Hi mrtaylor,

    There is a plugin that will show you the database queries and load time:

    http://wordpress.org/extend/plugins/memory-viewer/

    I'm not sure if that will do exactly what you're looking for, but it may help. This may help as well:

    http://wordpress.stackexchange.com/questions/31909/print-wordpress-template-filenames-for-debugging.

    My understanding of Template Hierarchy is that WordPress would only fall back to the next template file if the one it's searching for isn't there. If the file it's looking for is coded improperly, then you should see an error.

    Hope this helps!

  3. mrtaylor
    Member
    Posted 2 years ago #

    I found this from Eric P at http://wordpress.org/support/topic/get-name-of-page-template-on-a-page?replies=14

    it generates an error on the first line of output.. then still gives me what I want.

    // this can live in /themes/mytheme/functions.php, or maybe as a dev plugin?
    function get_template_name () {
    	foreach ( debug_backtrace() as $called_file ) {
    		foreach ( $called_file as $index ) {
    			if ( !is_array($index[0]) AND strstr($index[0],'/themes/') AND !strstr($index[0],'footer.php') ) {
    				$template_file = $index[0] ;
    			}
    		}
    	}
    	$template_contents = file_get_contents($template_file) ;
    	preg_match_all("(Template Name:(.*)\n)siU",$template_contents,$template_name);
    	$template_name = trim($template_name[1][0]);
    	if ( !$template_name ) { $template_name = '(default)' ; }
    	$template_file = array_pop(explode('/themes/', basename($template_file)));
    	return $template_file . ' > '. $template_name ;
    }

    with this for the footer:

    <?php
    if (is_user_logged_in()) {
    	echo ' | '. get_template_name() ;
    }
    ?>
  4. mrtaylor
    Member
    Posted 2 years ago #

    I'm worried that I might have accidentally deleted some code that told it to look somewhere, no error would be generated.

  5. ChristiNi
    Member
    Posted 2 years ago #

    Hello again mrtaylor,

    What's happening with your theme that makes you think it's falling back to a different template file? Can you provide a link to your site?

    Thanks!

  6. mrtaylor
    Member
    Posted 2 years ago #

    Sure! thanks for the help!
    I'm using the Under Construction plugin to hide it.
    My client doesn't want it public until it's ready.
    can you give me your IP address so I can add it to the whitelist?
    Or an email and I can give you the login. I checked out your profile.. helpful, prob not interested in hacking a tow truck website. :)

    -Matthew

    tbstowworld.com

  7. mrtaylor
    Member
    Posted 2 years ago #

    actually.. try here:
    http://tbs.matthewtaylorphotography.com/
    it's the same website. I also have a local copy.. they are all the same at the moment. onlu site url in dashboard is different.

  8. mrtaylor
    Member
    Posted 2 years ago #

    I think I may have messed up something when I built Anythingslider into the child theme. It's not the wordpress plugin.. it's the javascript plugin with a custom loop for the slider itself. loop-slider.php
    The front page is supposed to be a static page.. but it's showing loop-page with recent posts I think.
    maybe the slider loop has messed up the $query_string?
    I'm learning a lot by breaking and fixing things.. just got stuck on this one. The front page is supposed to have certain features.

  9. mrtaylor
    Member
    Posted 2 years ago #

  10. ChristiNi
    Member
    Posted 2 years ago #

    Hello again mrtaylor,

    Let me make sure I understand everything correctly.

    From your last post, it sounds like you were able to resolve this.

    If not, or you have issues in the future. If your have a copy of your files before adding in that slider, I would recommend reverting to that and then using this plugin to incorporate that slider into your child theme:

    http://wordpress.org/extend/plugins/anythingslider-for-wordpress/

    Let me know how this goes for you.

Topic Closed

This topic has been closed to new replies.

About this Topic