• I’d like to use a different post template (single.php) depending on the value of a customfield in that post. What file would I need to edit to acheive this and what would the PHP code be to do it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter zestylemon

    (@zestylemon)

    Is anybody able to offer any assistance?

    edit single.php:

    general idea (not a copy/paste instruction):

    direct at the beginning, make a mini loop and read the custom field:

    <?php while(have_posts()) : the_post();
    $value=get_post_meta($post->ID,'key',true);
    endwhile;
    if($value=='different') {
    global $post;
    include(TEMPLATEPATH . 'different_post_template.php'; }
    else { wp_reset_query(); }
    // from here this should be the code of the standard singe.php
    ?>

    fully untested –
    make backup copies of the template files before editing

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Template based on value of customfield’ is closed to new replies.