• Hi,

    how can i include .php file in to custom fields?

    My value is <?php include(TEMPLATEPATH . '/inc/sl/page_poster/index_page_poster.php'); ?>

    In single.php i have this code: <?php $values = get_post_custom_values('Page poster'); echo $values[0]; ?>

    Thanx for help.

    Martin

Viewing 3 replies - 1 through 3 (of 3 total)
  • Does your code give you the right string? It isn’t mangled? If it is a good string, you might be able to use eval to include the file.

    If you don’t mind my asking, why do you need to include this via a custom field instead of writing it into single.php, perhaps wrapped in a switch?

    Thread Starter Martin

    (@mcundric)

    If I typed in the box value just normal text, then the text is displayed correctly at the desired location.

    If I include php code, then I see nothing.

    Hmm … How do I use eval? I am a beginner in php.

    Custom fields: I want to use it because I do not want to use the post template files as templet_single_home.php, template_single_products.php. In such a case I would have to create too many template files.

    Thanx for your time!

    But you could include a keyword in your custom field and a switch in a single template.

    $values = get_post_custom_values('Page poster');
    switch($values) {
        case 'home' :
             include(TEMPLATEPATH.'/home_include.php');
             break;
        case 'products' :
             include(TEMPLATEPATH.'/products_include.php');
             break;
    }

    Its going to be easier to write and easier to maintain. Besides, eval() is a dangerous thing. You have to be very careful with it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘.php file include in custom fields’ is closed to new replies.