Support » Themes and Templates » Conditional Tag that Recognizes Page Template Type

  • Resolved Vendetta


    Is there a conditional tag that (or any other solution you can think of) that recognizes page templates? I have a set of buttons on my site that appear on particular pages using the is_page() tag. I have a number of pages that use one template in particular and it would save me a lot of trouble and coding if there was a function that recognized templates. Is there anything out there I can use?

    [sig moderated]

Viewing 3 replies - 1 through 3 (of 3 total)
  • What are you trying to accomplish?

    I use one template for many pages. At the beginning of the template I use the is_page(‘foo’) or is_page(‘bar’) to determine which page is loading it and go from there.

    Each Page when created has a special custom field added to it that holds the template’s filename (when no template is assigned, the value is ‘default’). So the following should work:

    global $post;
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if( $template == 'name-of-template.php') :
    ~ do this for Pages with template name-of-template.php ~
    <?php endif; ?>

    Thanks Kafka! Worked like a charm.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional Tag that Recognizes Page Template Type’ is closed to new replies.