0

I have since tried a blank and new php file and accessing it the same way - that worked. So I am now unclear why the existing file does not load at all. There are no errors. Here is the code start of the template part I am getting:

<?php
   require_once WP_PLUGIN_DIR.'/themename/includes/file1.php';
   require_once WP_PLUGIN_DIR.'/themename/includes/file2.php';
   require_once WP_PLUGIN_DIR.'/themename/includes/file3.php';
     
   if(isset($_GET["ict"])){
       $id_category[] = "'{$_GET["ict"]}'";
       $variable1= new file3();

I am trying to include a partial template and have read up on how to do so.

<div class="row">
    <div class="col-md-12">
        <?php get_template_part('/partials/category.php');
        ?>
    </div>
</div> 

The file I have included the above code in is in the theme main. The partial is in a folder in the theme main called partials. When I use /partials/category.php I get a blank with no PHP error in the area of the page where the information should be.

If I dont use the / on front of partials I get an error.

I have also tried removing the / on the front and at the same time removing the .php at the end. Same result where there is no error and no output

What am I missing about getting the template part to display>?

Here is the blank space where this should display enter image description here

18
  • 1
    What is the error you get? Why do you include the .php extension?
    – Tom J Nowell
    Mar 2, 2021 at 23:43
  • no error. Just tried it a number of ways. Its blank. I have since tried a blank and new php file and accessing it the same way - that worked. So I am now unclear why the existing file does not Mar 2, 2021 at 23:49
  • what do you mean by tried a blank? And when you said "I get a blank with no php error in the area of the page" can you be more specific? I can think of multiple things this could mean. e.g the page stops loading when it reaches that line, or the page runs as if the line isn't present, etc. Have you checked your PHP error log? Are you sure partials/category.php actually has output?
    – Tom J Nowell
    Mar 2, 2021 at 23:56
  • Thanks yes I am 100% it has output as it is used elsewhere successfully. I literally mean a blank in the space where I would expect to see the content. Just nothing there. Mar 2, 2021 at 23:58
  • if it's used elsewhere successfully then can't you copy paste that to this location? What does the inside of that file look like? I do not understand what you mean by a blank in the space, it does not make sense as a phrase, the grammar makes no sense, can you describe using different words?
    – Tom J Nowell
    Mar 3, 2021 at 0:00

1 Answer 1

0

Your get_template_part call is successful, it's the file it loads that is broken

<?php get_template_part( 'partials/category' ); ?>

If you swap the contents of that file for this:

<p>Hello World</p>

Then it will work as expected.

The cause of your problem is this:

require_once WP_PLUGIN_DIR.'/themename/includes/file1.php';
  • you should not be including files from other themes directly
  • themes don't go in the plugins/WP_PLUGIN_DIR folder
  • PHP can't find the file so it exits with a fatal error

You should see confirmation of this in your PHP error log

1
  • got it thank you for letting me know. Dealing with others code, when it isnt proper is rough Mar 3, 2021 at 18:39

Your Answer

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

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