• I’m not sure if I’m doing this the right way.

    What I want to do is to include a different slideshow with every different page. Each slideshow includes 4 or 5 images and is 4 or 5 lines of HTML

    I would like to include this on the page.php as a <?php include ()?>

    And I would like the include file to be determined by a custom field with the name “slide”.

    So if I create a page and the custom field has the value “home-slide”, I would like the page.php to spit out:

    <?php include(TEMPLATEPATH . '/home-slide.php'); ?>

    But I can’t work out how to achieve that in the loop. I have tried:

    <?php include(TEMPLATEPATH . '/<?php echo $slide; ?>.php'); ?>

    and

    <?php include(TEMPLATEPATH . '/<?php echo get_post_meta($post->ID, 'slide', true); ?>.php'); ?>

    but they don’t work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try:

    <?php
    $slider_file = get_post_meta($post->ID, 'slide', true);
    if( $slider_file != '' ) {
        $slider_file .= '.php';
        include get_template_directory() . '/' . $slider_file;
    }
    ?>
    Thread Starter Rob Cubbon

    (@robcub)

    Thank you so much, esmi, that works.

    I just found out that this works as well:

    <?php include(TEMPLATEPATH . '/'.get_post_meta($post->ID, 'slide', true).'.php'); ?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding as a custom field’ is closed to new replies.