Template part including not working

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
Template part including not working

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x