I want to create a special php and javascript page, but I want it to use my Wordpress theme that is already installed. How to do that?
Thanks
You can do this by including the header and footer from wordpress, and putting your own code in the middle. Such as this:
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/[YOUR THEME]/header.php";
// your code goes here
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/[YOUR THEME]/footer.php";
I haven't tested this on newer versions of wordpress, but in the past that has worked. You can even include the wpconfig file if you want to use some of those variables, such as the database connection information.
Hope this helps.
See Integrating WordPress with Your Website « WordPress Codex on how to pull the header and other includes into a static php page/file, like:
<?php
require('/the/path/to/your/wp-blog-header.php');
get_header();
?>
<?php
define('WP_USE_THEMES', FALSE);
require('./wp-blog-header.php');
get_header();
query_posts('showposts=1');
get_footer();
?>
Related
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 am using a custom CMS for a website that deals with 90% of the site's pages and content.
However, for the news/blog section of the site, I am using Wordpress.
I'm able to include the necessary Wordpress files to pull in posts to the main site, but cannot do the reverse.
I want to be able to call a php file into the header of Wordpress so I have access to the CMS's classes, primarily for navigation.
I've tried a search but can't seem to find an answer.
Additional Information:
Wordpress is installed in site.com/wordpress
The file I want to include is in site.com/includes
Clarification:
I don't want to create a custom template or include Wordpress functionality outside of Wordpress. I want to pull external classes from a CMS, which is a level above Wordpress, into Wordpress so that I can use it throughout the Wordpress installation.
You should go with custom page template.
Its an easy way to include php file in wordpress because in thisway you can easily include wordpress theme header and footer.
To create a custom page template.
You have to simply create new .php page and at start of page just include this code.
<?php
/*
Template Name: My custom page template name
*/
?>
// your code
To read in detail about Wordpress custom page template click here
I hope it will help you.
Method 1 :
<?php
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
Method 2 :
<?php
define('WP_USE_THEMES', false);
require('./wp-load.php');
?>
I managed to fix this by altering the include line to reference the folder above the Wordpress root.
So, the line became require_once "../path/to/file" instead of just require_once "/path/to/file"
I have added a php page (test.php) in my root directory (WWW) where wordpress is installed. I don't want to use the custom template method (add this page in my wordpress theme directory)
I have added in this php file this:
<?php
require('wp-blog-header.php');
get_header();
?>
<h1>Test</h1>
<?php
get_footer();
?>
When I do: www.example.com/test.php this page is correctly loading but the title of this page display "error 404"
I don't understand how can I resolve this problem.
you need to include wp-load.php to use header, in your case replace require('wp-blog-header.php'); with
<?php require_once('wp-load.php'); ?>
I have placed this code in my root directory in test.php file. This code is working fine if you replace require('wp-blog-header.php'); with require_once('wp-load.php');
I'm trying to incorporate some custom made php files in a WordPress site.
In these files made links to other files.
<?
echo "" $row['Name'] . "<br> ";
?>
This works fine with an php-execute plugin for WordPress. The only thing is that the show.php opens without the WordPress theme and layout.
How can I make a link so that a new php file will open in the same (side)bar/frame with the same layout as the WordPress page?
you need to create a custom template for that
The syntax is something like this:
<?php
/*
Template Name: My Custom Page
*/
get_header();
?>
Here your HTML coding goes
<?php get_footer(); ?>
This will give you the look and feel you are looking for!!
Found my own work around
Create a page in WordPress (page_id=x) and include an exec-php plugin.
Include this code on the page.
<?
$page_include =$_GET["page_include"];
include $page_include;
?>
If you want to show a custom page in the wordpress them make the following link:
<?
echo " link "
?>
I want to create a php page on the website (CMS Wordpress), but I do not understand how to incorporate the template files, for example
<?php get_header(); ?>
And other content. I know that it is possible to create pages through the admin interface, but I do not fit... if you try to create a page of template files and then go for it the direct link:
http://local/wp-content/themes/mytheme/mypage.php
with pre-embedding the code
<?php get_header(); ?>
it will fail like:
Fatal error: Call to undefined function get_header()
What should I do?
How i can "say" this CMS that the page is important for me, and it performs some functionality? That is, in fact, get the full url to her and that did not give out errors…
You need to include wp-load.php in your script to use any of WP functions:
<?
require_once('../../../wp-load.php');
get_header(); ?>
try that. xD