WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Includes and Conditional Statements (7 posts)

  1. elDeuce
    Member
    Posted 6 years ago #

    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?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Try this:

    <?php
    if (is_page('3')) {
          <?php include (bloginfo('template_directory').'/includes/form.php'); ?>
        }
    ?>
  3. elDeuce
    Member
    Posted 6 years ago #

    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
  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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?

  5. elDeuce
    Member
    Posted 6 years ago #

    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?

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  7. elDeuce
    Member
    Posted 6 years ago #

    the get_template_directory() was ace!

    thanks for the help, again!! :-D

Topic Closed

This topic has been closed to new replies.

About this Topic