0

I have created an example.php:

<?php  get_header();  
 get_template_part('template-parts/banner','title');  ?>

  <div class="container">
    <p>HERE GOES THE TEXT</p>   
  </div>

<?php get_footer(); ?>

in the page-main.php I have created a link: <a href="<?php echo site_url('/example.php'); ?></a>

When I click it I can see in (page.php/example-php) the header, the footer but NOT the html part. What am I doing wrong?

Please help and thank You for Your help.

After searching the net and reading, I figured that inserting this code:

  <?php while ( have_posts() ) : the_post(); ?>
  <?php the_content(); ?>
  <?php endwhile;
  ?>

made my day. Now I can display my page as a new separate page. So now all the code looks like this:

<?php  get_header();  
 get_template_part('template-parts/banner','title');  ?>

 <?php while ( have_posts() ) : the_post(); ?>
  <?php the_content(); ?>
  <?php endwhile;
 ?>

  <div class="container">
    <p>HERE GOES THE TEXT</p>   
  </div>

<?php get_footer(); ?>

But if You think that its wrong what I have done please let me know. I am learning so please forgive me for my lack of knowledge.

0

2 Answers 2

1

To expand on Tom's answer, you need to understand how templates are used by WordPress. They are the framework that 'builds' the page output. You use a template by creating a page, then selecting that template.

Start here to learn about templates https://codex.wordpress.org/Templates

Note that you should only create templates in your Child Theme. If you put it in an active (non-Child) theme, a theme update will remove your template. Always use Child Themes. There are many plugins that will quickly create a Child Theme, or you can learn about it here: https://developer.wordpress.org/themes/advanced-topics/child-themes/

1

Those are template files, you're not meant to access/visit/link to them directly, it's posts and pages that have URLs not PHP files.

Have a look at page templates, you'd be better creating a page, giving it a page template and linking to that page, not the PHP file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.