I created a footer.php file:
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col col-md-5">
<p>Copyright © 2018 Nens Events.</p>
</div>
</div>
</div>`
and it is located on a folder like this one:
/php/footer.php
All I want is to read it on a subfolder like this one: /events/na/1.php
but when I use this code, it doesn't read the footer.php file, does someone know what I am doing wrong?
<?php
echo file_get_contents("/php/footer.php");
?>
Use include() or require() function to join your codes into your script.
So the code for reading(in your terms) will be like this
<?php include 'php/footer.php'; ?>
If the site is on root page, use absolute path like this.
<?php include '/php/footer.php'; ?>
It should work! Give a try.
Use require('php/footer.php') for better coding.
Related
I'm trying to display the data of a ACF but I'm getting this error in Visual Studio Code:
This is the entire code. I tried reinstalling the plugin, added PHP to the path but nothing seems to be working.
Single.php
<?php get_header();?>
<div class="container">
<div class="row">
<div>
<img src="<?php the_post_thumbnail_url('thumbnail'); ?>" id="single_header">
<div id="single_content">
<?php if (have_posts()):while (have_posts()):the_post(); ?>
<?php
$fn=get_the_author_meta('first_name');
$lname=get_the_author_meta('last_name');
$email=get_the_author_meta('email');
?>
<h1 class="text=cenetr nt-3 mb-5 text-primary"><?php the_title();?></h1>
<small>Publishor:<?php echo $fn; ?></small>
<p><?php the_content();?></p>
<?php
endwhile;
endif;
?>
<?php previous_post_link(); ?>
<?php next_post_link(); ?>
</div>
<div id="single_extraInfo">
<p>Company: <?php the_field('flight_company'); ?></p>
<p>Date: <?php the_field('flight_date'); ?></p>
<p>Capacity: <?php the_field('flight_capacity'); ?></p>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
On top of what #DaleNguyen adviced above...
Make sure the directory that contains acf plugin is in your Vs Code. Example, instead of only opening the theme directory in Vs Code in which you are probably working, open the entire wp_content directory in your VS Code. That way, when intelephence run in the back-ground, it will be able to reach the plugins folder and acf functions in the acf plugin folder.
In the intelephense, make sure you add wordpress to the list.
#james-serengia answered with one working solution that the ACF plugin folder should be open in the same workspace as the code you are working on and the warning disappears.
Alternatively if that is inconvenient, you can add you can add the ACF stubs to VSCode. It is a bit of messing around but when it is done, it is done. See this explanation.
I added some php to some of my pages, but its not coming up on any of the pages.
<body class="menu">
<!-- Slide bar starts here -->
<?php require ('/Php/Slider.php');?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
in the php file I had this.
<header>
<a href="#" class="menu-toggle">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</a>
<nav class="menu-side">
<div class="listing">
<div class="box"><a class="list" href="/"><h1>Home</h1></a></div>
<div class="box"><a class="list" href="/DayZ_Home/"><h1>DayZ</h1></a></div>
<div class="box"><a class="list" href="/Photos/"><h1>Photos</h1></a></div>
<div class="box"><a class="list" href="/Store/"><h1>Store</h1></a></div>
</div>
</nav>
</header>
This is the exact same for all my pages, and nothing is coming up.
This is the error I get:
[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening '/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14
Any Idea what is wrong?
Simply try this first : Remove slash in front of php in the path and run again.
If that don't work continue reading.
Let me help you as much as I can.
First thing first, this
[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening'/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14
(just stating the obvious to me) This means,
There is a FIle called 'index.php' in public_html directory
It has a function "include()" on line 14 in its code.
The include function have a path in parenthesis following it.
There is a error in that path.
Either file "Slider.php" is not there or the script can't read it.
how do i know it for sure ?
Failed opening'/Php/Slider.php' for inclusion
Why did I tell this ?
It will help to understand errors next time.
Now let's try to solve the error, what I would do first to confirm the file permissions and every other thing is
Move the file to "public_html" folder itself.
new Path will be just Slider.php (Take note of the case).
Run your script and look for errors now.
That is the simplest way to do it.
Be very very precise in the "case" becuase I see you are not using the php conventions of naming everything.
Report back with the directory structure so we can help further.
'/Php/Slider.php' I assume you have Slider.php inside Php directory, Now the correct way to include would be:
require ('../Php/Slider.php');
Which will go back first, open the Php directory folder and look for Slider.php file.
<body class="menu">
<!-- Slide bar starts here -->
<?php require ('../Php/Slider.php');?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
EDIT:
Moving forward from the comments under this answer, you stated your directory structure as:
/public_html/index.php (home page)
/public_html/Php/Slider.php
Which means the approach I stated was fine.
To go from index.php to Slider.php the way would be:
../ (Go back)
Php/ (Open the Php directory)
Slider.php (Look for Slider.php)
Hence, require ('../Php/Slider.php');
As you mentioned that you are including this file in whole project , yet you did not mention the dirctory structure . It is always better to include files with absolute path .
try as below -
<body class="menu">
<!-- Slide bar starts here -->
<?php
$file=$_SERVER['DOCUMENT_ROOT']."<--your project dir-->".'/Php/Slider.php';
require ($file);
?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
<?php require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.php");?>
$_SERVER["DOCUMENT_ROOT"]. Makes your path start at /public_html/
so I have the include saved in a folder called "include" and the file name is menu. When I upload the site, it doesn't show. Do I need an extension? Do I have to do it with php? Help me please. Here's my code. the website is www.martinshaba.zzl.org
</head>
<body>
<div id="container">
<div id="header_line">
<div class="header">
<!--#include virtual="/inlcude/menu.html" -->
<p>MARTIN SHABA</p>
</div>
</div>
The #include tag is nothing to do with PHP, but is an Apache module. That module itself is, however, rarely used these days, and so you may do better to indeed use PHP, though you will have to name the file with a .php extension for that to be parsed.
<div class="header">
<?php
include "/include/menu.html";
?>
<p>MARTIN SHABA</p> <!-- etc.... -->
I building my 1st responsive & dynamic website. I tested it locally on WAMP and all my sections show up but when I moved it to my 1and1.com production server my php includes didn't work. I checked the PHP versions and WAMP and 1and1 are using PHP 5.4.
Can you tell me what I overlooked or did wrong?
The PHP code is:
<?php include_once('/includes/Footer.php'); ?>
My footer looks like this:
<div id="footer">
<footer class="row">
<div class="large-12 columns">
<hr>
<div class="row">
<div class="large-8 columns">
<p>Jersey City Dance Academy 107 Westside ave. Jersey City, NJ 07305</p>
</div>
<div class="large-4 columns">
<ul class="inline-list right">
<li>Terms of use</li>
<li>Privacy Policy</li>
<li>Site Map</li>
</ul>
</div>
</div>
</div>
<div class="large-12 columns">
<div class="row">
<div class="large-8 columns">
<p>(201) 435-8943 <a mailto="Info#JerseyCityDanceAcademy.com">Info#JerseyCityDanceAcademy.com</a></p>
</div>
</div>
</div>
</footer>
</div> <!-- end #footer -->
*******UPDATE Jan 25th, 2014*****************
I moved all CSS, JS & includes files so the webpage could find them in the relative path but my includes are still not showing up. Picture showing file locations in FTP program.
http://i.stack.imgur.com/R5H94.jpg
additional 1and1 may be Case sensitive while your WAMP isn't. Check case of your filenames, Footer.php is not footer.php
You are using absolute directories for the include command.
<?php include_once('/includes/Footer.php'); ?>
Absolute directory may be different in your new hosting. You should either check the directory in which the Footer is contained or use relative directories.
<?php include_once('includes/Footer.php'); ?>
This will give you a relative path, which your local and live server may read differently.
This assumes that the 'includes' folder is in the same place as index.php
Alternatively (and the recommended method) is to have a path to the root via a variable in front of your includes, like:
<?php include_once($site_root.'includes/Footer.php'); ?>
You could even define that as a constant or put all your important data (like root paths) in an array.
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();
?>