WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Using “php include” in the body of the post

[Resolved] Using “php include” in the body of the post

  • Hi!
    Is it possible to use php include in the body of the post?
    I’m trying to do it, but i don’t undestand if i’m making a mistake or if it’s impossible to do it.
    I would like to includ (with php) the signature in every post, because if i would like to change my signature, i hadn’t to modify every post.

    Thanks 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • You can do it if you install the Exec-PHP plugin. It’s a pretty popular plugin and should get you where you want to go.

    -WCC

    esmi

    @esmi

    Forum Moderator

    Only if you use one of the PHP plugins such as Exec PHP. Alternatively, you could include your sig file in single.php.

    Thanks!!! 🙂

    I tried to use php but i found that Exec-PHP allows php only in the pages and not in the posts (articles).
    Is it correct?
    Is there a way to insert php in the articles?

    Thanks 🙂

    esmi

    @esmi

    Forum Moderator

    I’ve not used any of the PHP plugins myself, so I’m afraid it’s just a case of trying the different plugins until you find one that suits your needs.

    If you are including your sig in every post, and you want them dynamic, meaning when you change your sig even old posts are affected, you are much better off adding the sig to the post template files than adding the sig in every single post. You would not have to think about it again at all. It will just automatically appear at the bottom of every post.
    Put the include you want add in the post in the template file.
    single.php for single page with comments
    index.php for posts page
    archive.php for categories, tags, archives etc.

    @stvwlf

    Thanks!
    The problem is that there are 4 differet authors and the sign is not the same :'(

    esmi

    @esmi

    Forum Moderator

    Try:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    [ usual post stuff ]
    <?php
    switch ($post->post_author) {
    
    	case 2:
    	include(TEMPLATEPATH . '/fred-sig.php');
    
    	case 3:
    	include(TEMPLATEPATH . '/bob-sig.php');
    
    	case 4:
    	include(TEMPLATEPATH . '/tom-sig.php');
    
    	case 5:
    	include(TEMPLATEPATH . '/john-sig.php');
    
    	default:
    
    }?>
    <?php endwhile; ?>
    <?php endif; ?>

    The numbers (2, 3, 4 and 5) refer to the ids of the various authors.

    Thaks to all!
    I’ve solved the problem.
    I installed the plug-in PHP Execution, then i tried to use the function “php include”, but there was an error:

    Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/user/public_html/page.php on line xx

    So, i solved the problem using this code for inclusion:

    <?
    $a = file_get_contents(“http://www.somedomain.com/file.php”);
    echo ($a);
    ?>

    As it was explained here

    Thanks 🙂
    I hope that this solution could help anyone 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Using “php include” in the body of the post’ is closed to new replies.
Skip to toolbar