Title: Adding  as a custom field
Last modified: August 19, 2016

---

# Adding as a custom field

 *  [Rob Cubbon](https://wordpress.org/support/users/robcub/)
 * (@robcub)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/adding-as-a-custom-field/)
 * 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)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/adding-as-a-custom-field/#post-1715561)
 * 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](https://wordpress.org/support/users/robcub/)
 * (@robcub)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/adding-as-a-custom-field/#post-1715577)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Rob Cubbon](https://wordpress.org/support/users/robcub/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/adding-as-a-custom-field/#post-1715577)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
