I have put some php code in a sidebar-01.php
i like in my template file to get that code
How do u do that ? (i don't what to change the code of WP for updating purpose)
i have try include('sidebar-01.php); - it don't work
i like to have a function like : get_header(); for my file, something like : get_file('sidebar-01')
is it possible ?
Go to the 'Theme Editor', look for sidebar.php. Edit it and place this code there:
include('sidebar-01.php');
Also, remember to place your sidebar-01.php in same folder as the other theme .php files (basically your theme folder).
Try the get_sidebar() function defined in wp-includes/general-template.php
If your sidebar file name is sidebar-home.php then call it like this
get_sidebar('home');
Related
The file is manually created by me & not a part of the theme.
I've tried by placing get_header( ) inside my file but it shows a error that get_header( ) is not defined.
Maybe you don't have default header and footer names. Then you need to set additional name.
Includes the header.php template file from your current theme's directory. If a name is specified then a specialised header header-{name}.php will be included.
If the theme contains no header.php file then the header from the
default theme wp-includes/theme-compat/header.php will be included.
Source: https://codex.wordpress.org/get_header
I highly discourage it but you need to include the wp-load.php file that resides in the root of your wordpress installation, in your lone php file. That is how you have access to WP functions and capabilities.
But again I HIGHLY DISCOURAGE IT. Find another way, create a simple plugin and activate it, in which you put that php file's code, or if part of a theme, just create a new page template with a different header, that you can call with get_header('name_of_header_without_php_extension') or a new footer called the same way but with get_footer().
There are alternatives, maybe if you share what you are trying to achieve, we can guide you to a better, safe solution.
Based on theme it's defer.
Same time define as get_header(),get_footer()
But now latest themse assign particular theme name based header & footer function
Ex: Theme Name is "Demo"
So the header function assign as Demo_get_header() or get_header_Demo()
Dashboard ->Appearance ->Editor -> in your Template file or in page.php write
<?php get_header()?>,<?php get_footer()?>
if you want to use different headers on different pages
1. create new file , name it header-example.php
2. you can call this header in any page using code
I can't seem to find any documentation on this so maybe someone here can help. I have been adding all my WooCommerce hooks to my functions.php file but I would rather have all of them in a separate file to keep things tidy. Obviously I will need another php file for these but how do I link it to the functions.php file so that the code runs as it does now? Thanks
just create new file with your woocommerce hooks code name anything what u want.
Ex. woocommercehook.php and place file in theme folder.
in function.php file just include your woocommercehook.php file at last.
include("woocommercehook.php");
Done. all work same as early.
The PHP include/include_once and require/require_once will work fine. However,
create another file with your hooks( woo-hooks.php ) and use WP get_template_directory to require the file.
require get_template_directory() . '/woo-hooks.php';
I decided to try building a theme without using a foundation like underscores etc... I have all the required files
(ss of files),
my functions.php file looks like this:
functions file,
and I am trying to load this file to enqueue all my css:
ss of enqueue-scripts file.
This has worked on other themes I did based off underscores so I assume I am missing some function that perhaps controls the pathing?
Added a message to console.log to see the pages were being loaded and on all of them I do get the message back, so I assume they must be pathing. Is there a way to check or set the get_template_directory_uri?
try this:
require __DIR__ . "/functions.php"
Thanks Gerald, was missing the wp_head
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():
get_template_part( 'page' );
// loads page.php from the theme directory.
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 mentioned include('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
include ('side.php');
OR
require ('side.php');
you may also use include_once / require_once
Please use require_once or include in php file like below.
require_once('side.php');
or
include ('side.php');
try this,
require( dirname( __FILE__ ) . '/page.php' );
if your page is in same level where is your parent page.
Add this code in your php page
<?php include_once('filename.php'); ?>
There are so many options that you can chose:
You can use get_template_part():
From the Docs: WordPress now offers a function, get_template_part(),
that is part of the native API and is used specifically for reusing
sections - or templates - of code (except for the header, footer, and
sidebar) through your theme.
Other solution is require_once() or include_once().
But if i compare both function include_once() is faster than to require_once() for smaller application.
For better understanding about the require and include you can read this Question.
I have a module of facebook login.
But it could be add in content top or content bottom I want to add it in header for users.
Could someone can tell me how to call a module named facebook_login.tpl as
<?php $facebook_login ?> in header.tpl file in Opencart 2.0.1.1.
You will call controller in header.php file. for eg. if you want to call controller of facebook_login.php file so you need to write code in header.php like :
$data['facebook_login'] = $this->load->controller('common/facebook_login');
and in header.tpl file you need to write code like :
<?php echo $facebook_login;?>
maybe it will be helpful
Thanks