I am working with wordpress.
I see that in my index.php there is a code called <?php get_footer(); ?>
..and I get it, it’s simple. This code will pull footer.php
.
It seems to me that the get_footer()
is built in to wordpress that pulls anything that is named footer.php
.
I have created my own page called page.php
.
I want to be able to ‘get’ this page and show in my php code enabled ‘sidebar widget’.
I have tried to paste this code, and I am more that certain that its wrong:
<?php
echo file_get_contents("side.php");
?>
What code would I need if I want my custom page called page.php
to be shown?
The WordPress way to load a template file is
get_template_part()
:Note that
page.php
is a special filename in WordPress themes, this file is loaded as a template if a page is displayed. You should give your file a different name if you want to prevent this.Details are in the already mentioned template-hierarchy.png
Edit:
After rereading your question: If your
page.php
is not from a template, but in a folder of a plugin you are developing as a sidebar widget, the also already mentionedinclude('page.php');
would be the way to go.page.php is a special page of wordpress. See this diagram.
https://developer.wordpress.org/files/2014/10/template-hierarchy.png.
The wordpress way is to create a own template.
https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
try the following
OR
you may also use include_once / require_once
Please use require_once or include in php file like below.
or
try this,
if your page is in same level where is your parent page.
Add this code in your php page
There are so many options that you can chose:
You can use
get_template_part()
:Other solution is
require_once()
orinclude_once()
.But if i compare both function
include_once()
is faster than torequire_once()
for smaller application.For better understanding about the
require
andinclude
you can read this Question.