included php "template" moved downwards [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Edit: Fixed, moved <?php include(haeder.php); ?> to the top and replaced the outsourced part with <?php showheader(); ?>.
I've been creating a little website, and as its menubar started to get full I wanted to "outsource" it to a separate file.
<body>
<div style="width:800px;margin:0px auto">
<!-- outsourced part -->
<div style="height:50px;background-color:#ff0000">
Header
</div>
<!-- end of outsourced part -->
<div style="margin-top:10px;background-color:#00ff00">
hello world
</div>
</div>
</body>
So I copied the outsourced part and pasted it into a new file called header.php and replaced it with
<?php include("header.php") ?>
so now the code is
<body>
<div style="width:800px;margin:0px auto">
<?php include('header.php') ?>
<div style="margin-top:10px;background-color:#00ff00">
hello world
</div>
</div>
</body>
Now when I open the website again the header and everything after it has moved downwards. How can I prevent this from happening? I have PHP 5.6.14 installed on XAMPP and PHP 5.3.3 on a Linux server.
Uploaded the 2 files here

I tested your file and I could see the issue. Usually this is because you got an invisible character in the page. So go into the Chrome debugger, Elements view, and expand the code. You'll find the following before your header <div> tag.
"
"
from the debugger, you can delete it, and you'll see your page displays fine again. So cleanup your 2 php file. One is having an invisible character.
I believe the reason is that your index.php file in UTF8-BOM encoded while the header.php is just UTF8 - make sure to use the same encoding to avoid these issues.

Related

WordPress Shortcode Crashes Site

So, to make my story a little short. I'm doing some changes to a client's website, a past freelancer made them a custom theme that made it extremely hard to actually do any changes to the website itself. I'm not that experienced in PHP but I'm learning as I go.
The client asks me to create a slider and I'm using SlideAnything slider plugin that includes shortcodes to be easily added to a page through the editor.
The Shortcode is this "echo do_shortcode("[slide-anything id="2320"]");"
And the way I inserted it in the website was like this:
<section id="feature-courses" class="pt pt-sm-80 feature-section">
<div class="wow fadeInLeft container text-center">
<h2>Cursos de Inglés Destacados</h2>
<div class="spacer-60"></div>
<div class="row">
<?php echo do_shortcode("[slide-anything id="2320"]"); ?>
</div>
</div>
</section>
However, whenever I add it, it crashes the site with a message that says
Parse error: syntax error, unexpected '2320' (T_LNUMBER), expecting ',' or ')' in /home/tuirland/public_html/wp-content/themes/laukoa-tuirlanda/page-homepage.php on line 61
I searched and the shortcodes.php file is inside the WordPress folder.
I recreated my client's website from the ground-up in my local environment and it works flawlessly, however, when I try to do it on his website, the whole thing keeps crashing.
Any reason as to why this is happening on his server but not on my local testing environment? any help would be appreciated. Thanks in advance.
When you using " after the ID atrribute, it's closing the do_shortcode function so it will throw an error. Your code should be:
<?php echo do_shortcode('[slide-anything id="2320"]'); ?>
Or:
<?php echo do_shortcode("[slide-anything id='2320']"); ?>

How to include and link menu file into every webpage using HTML?

I have researched some answers that talk about php, javascript, iframes etc. but I have tried a couple and none of them work. I am new to HTML coding.. and coding in general!
<link rel="menu" href="menu.html"> does nothing
<!--#include virtual="/menu.html" --> does nothing (presumably because its a comment?)
<iframe src="page.html"></iframe>
or object... both place the menu in a silly little scroll box.
I want to run my menu on my page as if it were a function in C. Where I can just include it, and it be there, or just link it.
Thanks for the help!
Ryan
webpage file: biology.html
menu file: menu.html
<div class="container">
<img src="homeicon.jpg" width="50" alt="Home">
<div class="redhover">
<div class="dropdown">
<button class="dropbtn">GCSEs</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">A-Levels</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">University</button>
<div class="dropdown-content">
Telecommunications
Electronic Engineering
</div>
</div>
<div class="dropdown">
<button class="dropbtn">More</button>
<div class="dropdown-content">
About me
Youtube
</div>
</div>
</div>
</div>
You can use php to include files on other pages. Here is some example code to get you started:
<?php
require_once('menu.php');
?>
You can put this in your HTML page appropriately, however you must make sure that php can be processed on your server and the file containing php code must end in the .php extension.
There are also other methods of including files via php, see here:
http://php.net/manual/en/function.include.php
and
http://php.net/manual/en/function.require.php
Edit - I'm not a big fan of this approach, but it will work on Github pages.
Create a file called nav.js with your menu defined as a js variable, then use javascript to insert it into an empty div created on each page. This way to update your nav you only have to ever edit nav.js Not pretty but it works
nav.js
var navigation = "<nav>";
navigation += "<ul>";
navigation += "<li>Home</li>";
navigation += "<li>About</li>";
navigation += "</ul>";
navigation += "</nav>";
document.getElementById("navigation").innerHTML = navigation;
Other pages
<div id="navigation"></div>
<!--rest of page goes here.-->
<script src="nav.js"></script>
Fiddle: https://jsfiddle.net/ze3hLxx8/1/
There are multiple ways to include a file into another depending on the backend technology you wish / want / need to use.
PHP
The most common way to do it in php is by using the include or require statement inside a php file.
In your specific case your biology.html file must be converted to a biology.php file and then you can add the relative code to include the file:
<?php include('menu.php');?>
This simple statement will add the content in your menu.php file to the current page. This will not work if php is not present on the server and obviously will not work locally without a local development environment
The differences between require and include can be found on the official documentation:
include: http://php.net/manual/en/function.include.php
require: http://php.net/manual/en/function.require.php
SSI
Another method is to use Server Side Includes. To use the SSI it must be supported and enabled on the webserver. To use SSI you need to change the extension from biology.html to biology.shtml and then add the following statement:
<!--#include file="menu.html" -->
More information on server side includes can be found on wikipedia: https://en.wikipedia.org/wiki/Server_Side_Includes

If variable equals something, make a have a href attribute [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Using advanced custom fields plugin on my wordpress site. I have a select option in one of the custom post types which determines if post going to be a link to another page or call out popup.
Here is how it looks.
<!-- here goes a code defining post type. Works fine -->
<?php $hmltype = get_field('post_url_or_popup'); ?>
<div class="tablecell midlineunit middle">
<a class="table midunithref mw1" <?php if ($hmltype == hml_url) { echo 'href="<?php the_field('hplb_url'); ?>" ' } endif; ?> >
</a>
</div>
Must be a syntax error, but I'm just starting out with php, so, kind of difficult to find the mistake.
What is hml_url? Is it a variable called $hml_url..? Back to your issues, you're using endif; here completely wrong. You can only ever call it if you instantiate it like this:
if(condition) :
do stuff;
endif;
Now to fix your print.
<a class="table midunithref mw1" <?php echo ($hmltype == hml_url) ? 'href="'. the_field('hplb_url'); .'"' : ''; ?> >
You'll need to figure out/tell us what hml_url is for us to solve your issue. You would've also seen the error if you turned your error reporting on. You can do this by adding this to the top of your script:
ini_set('display_errors', 1);
error_reporting(-1); // or you could do E_ALL

PHP Using a variable from an include [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I got a simple PHP code like this one:
<div id="master">
<div id="info">
<?php include 'division.php';
echo $winrate;
?>
</div>
<div id="lastmatches">
<?php include 'lastmatches.php';?>
</div>
</div>
</body>
As you see i want to echo $winrate, but $winrate is a variable that comes from lastmatches.php. So it will never work. Some has got an idea to echo $winrate in the div info? Im stuck and i hope you guys can help me out!
Thanks in advance!
You need to include lastmatches.php before to define $winrate.
But if this file outputs some content then you will want to use the caching system to output the right content at the right place.
<div id="master">
<div id="info">
<?php include 'division.php';
// begin cache
ob_start();
include 'lastmatches.php';
// end cache
$lastmatchescontent = ob_get_clean();
echo $winrate;
?>
</div>
<div id="lastmatches">
<?php echo $lastmatchescontent; ?>
</div>
</div>
</body>
i suggest you to follow MVC approach, if you do not want to use framework u can do something like this: https://github.com/LPodolski/basic_php_templating
this will allow code to be more readable, by separating concerns of generating output from getting data from db, parsing it etc

Get URL of current page using php and ssi

So I got a webpage written in HTML. Menu, Header and Footer are included using SSI (server side includes; .shtml). The website is running on an Apache server.
Now I want to build a language changer that changes the page from [server]/de/index to [server]/en/index in case you change the language from German to English.
Therefore I want to include this into the header. I already found out, that using PHP for getting the current URL is the best way to do it and within the index.html file for example the code is working.
But when I include the code into the SSI, it is returning nothing.
Any clues?
PHP-Code:
<?php
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
?>
Index.html:
<body>
<!--#include file="res/Common/header.shtml" -->
<nav>
<div id='cssmenu'>
<!--#include file="res/Common/menu.shtml" -->
</div>
</nav>
<!--#include file="res/Common/footer.shtml" -->
</body>
</html>
header.shtml:
<div align="right"><p style="margin-top:5px; margin-bottom:5px"><font size="2">Language Selector</font></p></div>

Categories