Nested php include files - Not showing content Wordpress - php

I have some php include files which are pulling through content to my main pages such as header.php
Within these php files I have other php includes which call different elements of the design.
It will displaying perfectly fine until I converted the flat HTML files into a Wordpress theme directory.
The main header.php file displays but any php includes within it do not. Please could someone help.
Here is an example of a php file header-withbooker.php
<?php include 'includes/content/headers/with-booker.php';?>
Within this file it then looks like:
<?php include 'includes/content/nav/top-nav.php';?>
<div class="container">
<div class="full-header">
<?php include 'includes/content/rating-box.php';?>
<h1>Your journey begins here</h1>
<h2>4-90 seater vehicles & drivers available worldwide</h2>
</div>
</div>
</header>
<!-- Close Header Box -->
<?php include 'includes/content/booking/main-booker.php';?>
Any idea what I am doing wrong?
Thank you in advance

You can include files in WordPress Like:
get_template_part( 'includes/content/headers/', 'withbooker' );
get_template_part( 'includes/content/nav/', 'top-nav' );
get_template_part( 'includes/content/booking/', 'main-booker' );
Hope this works for You.

Related

Is it possible to link to a header.php and footer.php from different folder sources?

I'm a beginner at PHP.
I have multiple webpages residing in different locations. So when I wish to link to header.php and footer.php from the webpages in different folders, is it possible to do so? As shown in the picture, I have to create three different folders, containing same files, header.php and footer.php, to be able to link from three different sources.
With Best regards!
Yes it is possible to use a single footer.php and single header.php files and load them anytime you need.
What I would suggest you can do is that you create an include folder, then inside the include folder create another folder called common where by you will place website that elements that are always the same throughout the website ie, footer and header.
then I would also place a functions file inside the includes where I will place my website functions. Included in this function file is a function that I will use anytime I want to use the header.php and footer.php files.
Functions.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
The loadView() function is used anytime you want to load these two dynamic files. This functions takes two parameters 1 optional. The first parameter is the name of the view you want to load which is header or footer then the second optional is the meta information important for the header file, as the page title and meta description needs to be dynamic and change according to the page.
header.php
<!DOCTYPE html>
<html>
<head>
<title><?=$meta['pagetitle']?><!-- Dynamic page title --></title>
<meta name="description" content="<?=$meta['pagedescription']?>"><!-- Dynamic description -->
<!-- load your styles -->
</head>
<body>
<header>
<nav>
<!-- Your page navigation -->
<ul>
<li>Home</li>
<li>About</li>
<li>Another Page
</ul>
</nav>
</header>
footer.php
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
Main website pages
Your main website pages are pages such as index, about,services etc.
In these pages you would load the functions file, then be able to load the header and footer.
index.php
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
About Page
<?php
include 'includes/functions.php';
$meta = array(
'pagetitle' => 'About Us',
'pagedescription' => 'This is about page'
);
loadview('header',$meta);
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<!-- load footer -->
<?php
loadview("footer");
?>
Hope this gives you the idea on how you could achieve your goal, there are many ways you can achieve this.
Let me know when you need any help
Assign values for $h_path and $f_path dynamically.
<?php
$h_path = '';
$f_path = '';
include($h_path.'header.php');
include($f_path.'footer.php');
?>
My apologies for not providing enough information about the issues. My issue is that, when the index.php refers to the header and footer by "includes/header.php" and "includes/footer.php" respectively, and other webpages are located inside another folder which needs to access the includes folder via "../includes/header.php". There is no problem while referring to the files but the issue occurs when headers.php targets the webpages inside when it is written to only work with index.php. For example, would only work on index.php but not on the php files inside the folder which needs , But I'll try with $h_path = ''; and $f_path = '' soon.

linking to another php page and include header and footer

I am a beginner, just trying to learn php. Below is my index.php file:
<?php
include("header.php");
require_once('connect.php');
include("home.php");
include("footer.php");
?>
I made a simple test site that has the home page included inside the index.php file. Do I have to use include(header.php); on every page if I want to include the same code?
Thanks.
You dont have include header.php on every page.
Try this:
<?php include("header.php");?>
<div class="container">
<?php include ("home.php");?>
</div>
<?php include ("footer.php");?>
Keep the header and footer, just change the contents( home.php, otherpage.php, ... ).
I recommend you to use jQuery to dynamically load the content of container

How to Make or Call sidebar in CakePHP

I have such type of code in view, add.ctp file in Cake PHP.
<div id="container">
<div id="content">
------------------
</div>
<div id="sidebar">
----------------
</div>
</div>
Now in Layout, in default.ctp file, we access this code by this line.
<?php echo $this->fetch('content'); ?>
I have sidebar in each and every view file, and if I need some changes then I will go in each and every file and then change.
Now My Question is that, can I made a file in layout like sidebar.ctp or any thing else that I just call this file in my view. If I can, then how I will made such type of file.
You could do it with include or elements like this
<?php echo $this->element('sidebar'); ?>
With the element, you make the sidebar.ctp file in the View/Elements/ folder.
Check for more information: Cakephp 2 Elements
The other way is with include (not my choice, but another way to accomplish it)
<?php include('../View/Layouts/sidebar.ctp'); ?>
You can use elements and if the content in elements is dynamic you can use the blocks supported in latest version of cakephp.
http://book.cakephp.org/2.0/en/views.html

linkage through mapped php pages from menu

To try to map up all the pages, I've made a couple of maps called products and similar naming.
However when I go through a link with, for example, product/xxx.php and press the same link within the menu at that page I've entered, I get an adding of products/products/xxx.php, which break the link.
How do you avoid or correct these sort of linkages?
so for example I have my main menu inside a php file called menu.php which I include in the index.php by php include
a snip of the main menu php is
<div class="menuBar">
<ul id="menu">
<li>xxx
<div class="dropdown_unit">
<!-- Header -->
<div class="unitSizer">
<h4>xxx</h4>
</div> <!-- END Header -->
and it is placed within a div at the index.php
like this:
<div class="menuBar">
<?php include 'menu.php'; ?>
</div> <!-- END menuBarDental -->
this is just 1 part of the menu but it looks the same overall inside the menu.php
the problem here is that it seems by include this php file into the index.php and generating
the links inside the menu it keeps adding instances of the links.

Include URL in php

My form create by php script and between teo file:
index.php
header.php
In index.php, i try in
...
<div class="art-header-png"></div>
<div class="art-header-jpeg"></div>
<?php include("header.php"); ?>
</div>
<div class="art-nav">
<div class="l"></div>
<div class="r"></div>
and my header.php
<div class="art-logo">
<h1 id="name-text" class="art-logo-name">Your Title Goes Here</h1>
<div id="slogan-text" class="art-logo-text">Your Slogan Goes Here</div>
</div>
But it didn't show content inside header.php.
How can i make it work?
First thing, either place header.php in the same folder as index.php or specify the correct path relative to index.php when you are using include (same apply to require).
PHP Include
also check to see if your php is configured correctly as well. Save the following line of code in a php file. Run it and see if you get php window:
<?php
phpinfo();
?>

Categories