WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional Tag that Recognizes Page Template Type (4 posts)

  1. Vendetta
    Member
    Posted 6 years ago #

    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?

    V
    [sig moderated]

  2. drphil9001
    Member
    Posted 6 years ago #

    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.

  3. Kafkaesqui

    Posted 6 years ago #

    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:

    <?php
    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; ?>
  4. Vendetta
    Member
    Posted 6 years ago #

    Thanks Kafka! Worked like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic