• Resolved eldeuce

    (@eldeuce)


    I searched for this, because it’s hard to believe I am the first to attempt this, so i am sure it has been answered before, I’m just familiar enough with PHP and WordPress lingo to find it.

    I want a contact form to be php included into a page

    <?php include ("includes/form.php"); ?>

    was what i was using before I moved over to WP.
    Now WP has the tag

    <?php bloginfo('template_directory'); ?>

    where it will automatically grab the directory for me

    Also, I am using the conditional statement so the form only shows up on one page.

    So I am trying to figure out how to get

    <?php
    if (is_page('3')) {
          <?php include ("bloginfo('template_directory')/includes/form.php"); ?>
        }
    ?>

    all that to work.
    obviously this code does not work, but does anyone have any ideas of what might work?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Try this:

    <?php
    if (is_page('3')) {
          <?php include (bloginfo('template_directory').'/includes/form.php'); ?>
        }
    ?>
    Thread Starter eldeuce

    (@eldeuce)

    Your code leaves me with

    Parse error: parse error, unexpected '<' in /homepages/6/d214241798/htdocs/3dss/wp-content/themes/3dss/index.php on line 17

    if I change it to

    if (is_page('3')) {
          include (bloginfo('template_directory').'/mail.php');
        }

    then at least the site shows up but I get

    Warning: main(/mail.php) [function.main]: failed to open stream: No such file or directory in /homepages/6/d214241798/htdocs/3dss/wp-content/themes/3dss/index.php on line 17
    
    Warning: main() [function.include]: Failed opening '/mail.php' for inclusion (include_path='.:/usr/local/lib/php') in /homepages/6/d214241798/htdocs/3dss/wp-content/themes/3dss/index.php on line 17
    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    I was just editing the code you used, I didn’t notice your incorrect php tags.

    And why did you change it to “mail.php”? Why not tell me what you’re actually trying to do here. Where are your files actually located?

    Thread Starter eldeuce

    (@eldeuce)

    I use both form.php and mail.php – this one just happened to be named mail.php, sorry.

    i took it out of the includes folder, in hopes that it might help… no such luck.

    I verified that the mail.php is uploaded, so that shouldn’t be the issue. Why else would it fail to open?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    If these files are in your template directory, then the correct code should be this:

    if (is_page('3')) {
          include (get_template_directory().'/mail.php');
        }

    The bloginfo template function returns the URI, not the actual path.

    Thread Starter eldeuce

    (@eldeuce)

    the get_template_directory() was ace!

    thanks for the help, again!! 😀

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Includes and Conditional Statements’ is closed to new replies.