Results 1 to 5 of 5

Thread: Put a PHP call within a PHP call?

  1. #1
    robcub is offline Hello World
    Join Date
    Mar 2009
    Posts
    25

    Default Put a PHP call within a PHP call?

    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:

    Code:
    <?php include(TEMPLATEPATH . '/home-slide.php'); ?>
    But I can't work out how to achieve that in the loop. I have tried:

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

    Code:
    <?php include(TEMPLATEPATH . '/<?php echo get_post_meta($post->ID, 'slide', true); ?>.php'); ?>
    but they don't work.

  2. #2
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

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

  3. #3
    robcub is offline Hello World
    Join Date
    Mar 2009
    Posts
    25

    Default

    Thank you so much, Andreas. The second one worked.

    Seems obvious now, but I was stuck for ages on this. Cheers.

  4. #4
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    echo is for displaying something on the page, whereas what you were trying to do was to call another file (which may or may not echo something itself).

    This stuff is confusing for a start, but you will soon get the hang of it :)

  5. #5
    robcub is offline Hello World
    Join Date
    Mar 2009
    Posts
    25

    Default

    Quote Originally Posted by Ryan View Post
    This stuff is confusing for a start, but you will soon get the hang of it :)
    Sure hope so, Ryan. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •