-3

I am using wordpress as a platform for my website where i am trying to add some custom PHP files with keeping the same style used on the selected theme.

The problem is that the content of the webpage is not showed up on the website, although I created a template for the PHP file and i select the created template.

All my researches say that in order to create a custome PHP file in the wordpress is to :

  1. duplicate the page.php
  2. add this code at the top of the new file

    /*

    Template Name: templatename

    */

  3. add the PHP code

enter image description here

code:

<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package personalio
 */

        /*
        Template Name: ajwa2template
        */

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main">


            <?php
            while ( have_posts() ) : the_post();
            ?>
             <!--**********************************-->  

<html>

<head>
  <title>Form Validation</title>
  <!-- Latest compiled and minified BootStarp CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <!-- jQuery library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script type="text/javascript">
    jQuery(function() {
      jQuery("#textarea").hide()
      jQuery("#droplistID").change(function() {
        jQuery(this).val() == 'select' ? jQuery("#textarea").hide() : jQuery("#textarea").show();
      });
    });
  </script>

</head>

<body>
  <div id="page-wrapper">
    <div class="container">
      <form name="myForm" class="form-horizontal" id="myform" action="#" onsubmit="return submitForm();" method="POST" enctype="multipart/form-datam">
        <div class="panel panel-info">
          <div class="panel-body">
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label for="name" class="col-md-4">Date *</label>
                  <div class="col-md-6">
                    <input type="text" class="form-control" id="name" name="name" placeholder="Enter Name" required/>
                  </div>
                </div>
                <div class="form-group">
                  <label for="Title" class="col-md-4">Title *</label>
                  <div class="col-md-6">
                    <input type="text" class="form-control" id="mobile" name="phone" placeholder="Enter the Title" required/>
                  </div>
                </div>
                <div class="form-group  ">
                  <label for="category" class="col-md-4">select Category *</label>
                  <div class="col-md-6">
                    <select name="droplist" id="droplistID">
                           <option id = "option1" value="select" selected>Select</option>
                           <option id = "option2" value="category 1">category 34</option>
                           <option id = "option3" value="category 2">category 2</option>
                           <option id = "option4" value="category 3">category 3</option>
                       </select>
                  </div>
                </div>

                <div id="textarea">
                  <div class="form-group  ">
                    <div class="col-md-6">
                      <textarea cols="60" rows="15" placeholder="enter a text "> </textarea>
                    </div>
                  </div>
                </div>

                <div class="form-group  ">
                  <label for="image" class="col-md-4">Select Image </label>
                  <div class="col-md-6">
                    <input type="file" class="form-control" name="image">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-md-4 col-md-offset-4" style="margin-bottom: 50px;">
          <center>
            <input type="submit" class="btn btn-primary" value="Submit" />
          </center>
        </div>
      </form>
    </div>
  </div>
</body>

</html>


<!--***************************************************-->   
            <?php
                get_template_part( 'template-parts/content', 'page' );

                // If comments are open or we have at least one comment, load up the comment template.
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;



            endwhile; // End of the loop.
            ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();
Gianluca
  • 3,227
  • 2
  • 34
  • 35
Ghgh Lhlh
  • 155
  • 1
  • 3
  • 14
  • 2
    So what exactly is your problem with the code and what error are you getting? Please provide more informations. – Manuel Mannhardt Jan 30 '18 at 09:23
  • @ManuelMannhardt the problem is that when i try to enter the webpage its empty i will add the screenshot to the question – Ghgh Lhlh Jan 30 '18 at 09:27
  • Possible duplicate of [PHP's white screen of death](https://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – CBroe Jan 30 '18 at 09:27
  • 2
    _“the problem is that when i try to enter the webpage its empty”_ - then go enable WP debug mode and proper PHP error reporting first of all. – CBroe Jan 30 '18 at 09:28
  • 1
    why do you have html, body, head etc in your template - get_header should do that for you – Stender Jan 30 '18 at 09:31
  • @Stender ok i deleted the tags html , head and body but still noting is being displayed – Ghgh Lhlh Jan 30 '18 at 09:41

2 Answers2

0

Everything is wrong with your template. get_header() is calling Doctype and the head tag, probably a bit more stuff. You added another html document inside of a html document. Try this:

<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package personalio
 */

        /*
        Template Name: ajwa2template
        */

get_header(); ?>
  <script type="text/javascript">
    jQuery(function() {
      jQuery("#textarea").hide()
      jQuery("#droplistID").change(function() {
        jQuery(this).val() == 'select' ? jQuery("#textarea").hide() : jQuery("#textarea").show();
      });
    });
  </script>


    <div id="primary" class="content-area">
        <main id="main" class="site-main">

        <!--**********************************-->  
  <div id="page-wrapper">
    <div class="container">
      <form name="myForm" class="form-horizontal" id="myform" action="#" onsubmit="return submitForm();" method="POST" enctype="multipart/form-datam">
        <div class="panel panel-info">
          <div class="panel-body">
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label for="name" class="col-md-4">Date *</label>
                  <div class="col-md-6">
                    <input type="text" class="form-control" id="name" name="name" placeholder="Enter Name" required/>
                  </div>
                </div>
                <div class="form-group">
                  <label for="Title" class="col-md-4">Title *</label>
                  <div class="col-md-6">
                    <input type="text" class="form-control" id="mobile" name="phone" placeholder="Enter the Title" required/>
                  </div>
                </div>
                <div class="form-group  ">
                  <label for="category" class="col-md-4">select Category *</label>
                  <div class="col-md-6">
                    <select name="droplist" id="droplistID">
                           <option id = "option1" value="select" selected>Select</option>
                           <option id = "option2" value="category 1">category 34</option>
                           <option id = "option3" value="category 2">category 2</option>
                           <option id = "option4" value="category 3">category 3</option>
                       </select>
                  </div>
                </div>

                <div id="textarea">
                  <div class="form-group  ">
                    <div class="col-md-6">
                      <textarea cols="60" rows="15" placeholder="enter a text "> </textarea>
                    </div>
                  </div>
                </div>

                <div class="form-group  ">
                  <label for="image" class="col-md-4">Select Image </label>
                  <div class="col-md-6">
                    <input type="file" class="form-control" name="image">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-md-4 col-md-offset-4" style="margin-bottom: 50px;">
          <center>
            <input type="submit" class="btn btn-primary" value="Submit" />
          </center>
        </div>
      </form>
    </div>
  </div>


<!--***************************************************-->

            <?php
            while ( have_posts() ) : the_post();


                get_template_part( 'template-parts/content', 'page' );

                // If comments are open or we have at least one comment, load up the comment template.
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;



            endwhile; // End of the loop.
            ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();
?>
Zex2911
  • 1
  • 2
0
<?php /* Template Name: CustomPageT1 */ ?>

<?php get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();

            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            // End of the loop.
        endwhile;
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>