WordPress.org

Ready to get started?Download WordPress

Forums

How do I call a file from the text widget? (6 posts)

  1. Calvin Nix
    Member
    Posted 2 years ago #

    Hi, I try to keep this short. I have html code in the text area of a text widget. Its code for a table that is working fine but it is getting to large to maintain in the text box. Modifying the file outside of the box and then cutting and pasting into it has worked fine, but it would be nice if I could just use code to call the file "within" the text box widget itself. I have placed the table code in a file called: footercode.html, and I have used the following code in the text widget box:

    <?php
    $file=fopen("footercode.html","r");
    ?>

    and placed the footercode.html file in the theme directory, but of course it doesn't work, else I wouldn't be here. If someone could let me know what I am doing wrong i'd appreciate it. Thanks.

  2. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    You can use HTML in the Text Widget, but just like pages and posts, not PHP.

    The Text Widget can hold a variety of HTML, XHTML, and multimedia links and players such as video and object embeds.

    http://codex.wordpress.org/WordPress_Widgets#Using_Text_Widgets

    You could likely iframe it.

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    use a plugin to get a php enabled text widget;
    for instance: http://wordpress.org/extend/plugins/php-code-widget/

  4. Calvin Nix
    Member
    Posted 2 years ago #

    Unless I'm misunderstanding something, you have the option at the bottom of the text widget to handle PHP as it clearly says:

    Execute code within <?php ?> tags

    I have this box checked. When I use the code as mentioned in my initial post it recognizes it, but I get the following error:

    Warning: fopen(footercode.html) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\www\wordpress\wp-content\themes\mystique\atom-widgets.php(4774) : eval()'d code on line 2

    I'm guessing the PHP code I'm using in the text box has an error on line 2, being:

    $file=fopen("footercode.html","r");

    perhaps the syntax is wrong, as I got this online somewhere.

  5. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    Execute code within <?php ?> tags

    That is from a plugin or theme, not default WordPress.

  6. Calvin Nix
    Member
    Posted 2 years ago #

    That is from a plugin or theme, not default WordPress.

    Yes, that is true, however I have executed PHP from within the themes text box before without trouble. Apparently, it is something I'm doing wrong, either with the code or placement of the file, or....

    Back to my initial concern though, I don't have to use the code I'm using. Anything that works, whether it is PHP or something else would be great. I just want something that will "go get a file" when called from a text box. Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic