PHP files which I have include doesn't appear in php file - php

ANSWER: Was a problem with web hosting.
This is my code
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" lang="en" content="Test Website " />
<meta name="author" content="">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title</title>
</head>
<body>
<section id="wrapper">
<?php include('includes/topHeader.php'); ?>
<?php include('includes/leftSide.php'); ?>
<?php include('includes/middleSide.php'); ?>
<?php include('includes/rightSide.php'); ?>
</section>
<?php include('includes/foot.php'); ?>
</section>
</body>
</html>
question the other php files not appear in the main page?
to create it I have use this website
http://www.1stwebdesigner.com/css/how-to-create-php-website-template/
Update
View Source shows:
<section id="wrapper">
<!--?php include('../includes/topHeader.php'); ?-->
<!--?php include('../includes/leftSide.php'); ?-->
<!--?php include('../includes/middleSide.php'); ?-->
<!--?php include('../includes/rightSide.php'); ?-->
</section>
<!--?php include('../includes/foot.php'); ?-->

You are using the include function right, so please make sure that:
Files you are trying to include really exists, you can test with file_exists function
You don't have any fatal errors somewhere in the files that stops the execution of your program (you can check error log)
Your markup is well formatted (in some cases when code is not formated correctly browsers cannot render the page correctly)

On a quick note apart from what was already suggested. Try
<?php include('../includes/topHeader.php'); ?>
<?php include('../includes/leftSide.php'); ?>
<?php include('../includes/middleSide.php'); ?>
<?php include('../includes/rightSide.php'); ?>
I say this with an assumption that the include folder resides above the current file in the folder structure.

Related

Why won't my html render in my header.php file?

I have a barebone header.php file that looks like this so far
<!doctype html>
<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header class="testB">
<p>header section</p>
</header>
The header loads into the index.php file perfectly fine, however it doesn't render my <header> tag with the text. I just checked out a couple videos and tutorials to see if there's something else I need to do and they all seem to dive right into customizing everything and have it render. The only thing present is the title of my website which wordpress injects on its own. Any clue as to why this won't just work like it seems to in the tutorials?
Here's my index.php and footer.php just so you guys can see the overall setup.
index.php
<?php get_header(); ?>
<p class="test">body</p>
<?php get_footer(); ?>
footer.php
<footer>
<p>footer</p>
<?php wp_footer(); ?>
</footer>
</body>
</html>
Now that I posted this is just hit me that WP strips the <p>footer</p> out of the footer.php as well while injecting it's "powered by wordpress" snippet. I haven't enabled any WP theme support in the functions.php file yet as I haven't seen anyone doing anything like that before diving right into customizing their html.
UPDATE
I added the wp_body_open() function as suggested below by #amerinediary and my code still isn't rendering in the browser.
You're missing the wp_body_open() function.
Fire the wp_body_open action.
Which is getting triggered after the opening body tag, via the do_action( 'wp_body_open' ) hook.
Source # https://developer.wordpress.org/reference/functions/wp_body_open/
Following are default blank template part boiler plate
//header.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' );?>">
<?php wp_header(); ?>
</head>
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
//index.php
<?php get_header(); ?>
<?php get_footer(); ?>
//footer.php
<?php wp_footer(); ?>
</body>
</html>
Additionally <?php wp_footer(); ?> shouldn't be included inside a container as Wordpress is using it to render <script>'s tags.

How to include a php file with in WordPress header file

Hi there I seem to have run into an issue that I'm not quite sure about. I have a just developed a new WordPress theme for my personal website and I have some include files in the header which aren't being added.
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
<title><?php wp_title(); ?></title>
<!-- Google Analytics Tracking-->
<?php include_once("/inc/google-analytics-tracking.php") ?>
<!-- Drip Tracking -->
<?php include_once("/inc/drip-tracking.php") ?>
<!-- Hotjar Tracking -->
<?php include_once("/inc/hotjar-tracking.php") ?>
<!-- ConvertFlow Tracking -->
<?php include_once("/inc/convertflow-tracking.php") ?>
<!-- Share This -->
<?php include_once("/inc/share-this.php") ?>
<?php wp_head(); ?>
</head>
You can see my site here: https://www.elliottdavidson.com/. I'm not sure why the includes arent working? If anyone could shed any light on this it would be great.
/inc/ - it's an absolute path, if you want to use relative paths you have to write this string as inc/ because / means "root" directory of the linux file system.
I figured this out, in the end, the files don't want to be added into the header.php file but into the functions.php file like so:
// Google Analytics Tracking
require get_template_directory() . '/inc/google-analytics.php';

PHP include a file with an included file -> scripts and variables get included but seem echo'd

I am having troubles with including a file that has an included file with some js script library's in it.
index.php
<?php
include 'header.php';
?>
<section>
<div>
<p>misc. html</p>
</div>
</section>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
footer.php
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/includes/footerscripts.php');
?>
</body>
</html>
/includes/footerscripts.php
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<?php
$testVar = 'test';
?>
In that scenario, the index file does have this in the source code when ran:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
test =
The scripts are making their way there but are not being executed and the variables aren't coming through either.
When I change the footer.php to include those scripts and variable directly, the variable makes it to index.php, so do the scripts but they don't execute (or not on time?).
Any ideas guys?
I have a weird php5.ini file as I didn't know what all to put in it, if that makes a difference. The include file path seems okay as it still works for the most part.
Thanks,
Matt
Edit: Added the include ('header.php') which works fine and pulls in my header.
That file looks like:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="--">
<meta name="keywords" content="--">
<meta name="author" content="--">
<title>--</title>
<link rel="stylesheet" href="/css/mainstylesheet.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="icon" href="/images/favicon.ico">
</head>
<body>
<header class="nav-top" id="top" role="navigation">
<div class="container">
<div class="home-link">
<img src="/images/logo/logo-p.png" alt="plc" class="logo" />
</div>
<nav class="nav-main">
<ul>
<li>
Home
</li>
<li>
Portfolio
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Edit: Guess I just needed my jquery loaded from the header of the document, because it works that way. I still can't carry variables from grandchild to parent but oh well
According to your example the index.php file is missing something:
<?php
include ($_SERVER['ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
I assume that you didn't post the whole file, since here the output hmtl here is not valid - missing html opening tag, etc. Could you please provide the whole and/or simplified index file?
Replace all instances of $_SERVER['ROOT'] with $_SERVER['DOCUMENT_ROOT'].

PHP - HTML Script being placed within 'body' tags

I have been developing a page on my webserver (using nano on the actual server) and I have been experimenting with the INCLUDE statement as an attempt to hide database details from the end user. However, my html is being placed within BODY tags according to Firefox's Inspector.
Here is the result in firefox and below that is the code for my page.
<?php
include "/database.php";
?>
<DOCTYPE! html>
<html>
<head>
<title><?php echo $minfo['name']; ?></title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome to my page</h1>
</body>
</html>
If its needed I can also include the "DATABASE.PHP" script.
Try this:
<?php
include "/database.php";
?>
<!DOCTYPE html>
<head>
<title><?php echo $minfo['name']; ?></title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome to my page</h1>
</body>
</html>
Assumes that $minfo['name'] is defined in your database.php.

How do I set base URL for all pages of my website?

How do I set a base URL for my website and get it to include in every page?
Is there a way for me to easily change a variable to be the base url for the website, such as <?php $baseurl = "http://www.website.com/website/"; ?>, and include this on every page so that all CSS, JavaScript, images and PHP includes follow this $baseurl?
You can’t make both PHP and client-side assets use the same base URL, unless you use PHP to echo a base URL variable or constant to the page.
The usual approach is to have a bootstrap file that you include on every page, and define your base URL and other site-wide variables in there.
bootstrap.php:
<?php
define('BASE_URL', 'http://example.com');
index.php:
<?php
include('bootstrap.php');
?>
<!DOCTYPE html>
<html>
<head>
<!-- // -->
<link rel="stylesheet" href="<?php echo BASE_URL; ?>/css/styles.css" />
</head>
<body>
<!-- // -->
</body>
</html>
You may want to take a look at the html base tag.
Inside the <head> section of your html, put
<base href="http://www.website.com/website/">
On top of that, you may want to have a base.php with default directories and whatnot that you include into your project.
(xampp), the
How do I use on the local computer.
folder layout,
http://www.resimagaci.com/img/90rvnrf.png
ust.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
alt.php
</body>
</html>
sabitler.php
<?php
#sabitler
define('BASE_URL', 'base-url');
?>
index.php
<?php
include 'kutuphane/sabitler.php';
?>
<?php
$ust= BASE_URL . '/kutuphane/ust.php';
$alt= BASE_URL . '/kutuphane/alt.php';
?>
<?php
include ($ust);
?>
<?php
include ($alt);
?>

Categories