How can I apply a class to a PHP line? - php

I have <?php get_header(); ?> for the header
and want to add in class="sticky" so that when it's parsed to HTML it will read <header class=sticky">
Where/how would I do this? Various places I've tried within the PHP line gives me an error message **Parse error: syntax error, unexpected '?' in /home2//public_html/wp-content/themes/conf-theme/page.php on line 1**

Open the header.php file and add the sticky class to
<header id="masthead" class="site-header" role="banner">
The get_header function
Includes the header.php template file from your current theme's directory.
EDIT
jQuery
<script type="text/javascript">
$(document).ready(function()
{
$("header").addClass("sticky");
});
</script>

Related

Failed opening and inclusion

I really hope that someone can help me, because I have tried everything now in 4 days, and I am just stuck. I had a question with this before that did not get solved.
When I click one of my buttons "register" I get the following error:
Warning: include(resources/includes/header.html): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5
Warning: include(): Failed opening 'resources/includes/header.html' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5
Here is the relevant code:
header.html:
<!-- 1 button in the header -->
<li>
Register 1 <!-- Error -->
</li>
<!-- registernumbers.php is called fine. I can see my <h1> and <h2> text -->
registernumbers.php:
<?php
if( !isset( $_SESSION ) ) session_start();
?>
<?php include 'resources/includes/header.html'; ?>
<h1>Register Numbers</h1>
<h2>global/registernumbers</h2>
My folder structure is looking like this:
../../php/resources/includes/header.html
Is working, but the CSS is ofcourse not called.
resources/includes/header.html
This is the correct path, but here I get the error
<?php include(ROOT_PATH . 'resources/includes/header.html'); ?>
Does not work either
The path to the header is correct, and I even tried to uinstall MAMP.
When I use this:
When I put the header.html and registernumbers.php, where my index.php is, everything is working fine.
Does anybody have a clue on what I can do? I would really like to seperate my files in folders like this.
Updated code after response
<?php
if( !isset( $_SESSION ) ) session_start();
?>
<?php define 'APP_ROOT', '/resources/includes/header.html'; ?>
<h1>Register Numbers</h1>
<h2>global/registernumbers</h2>
<?php define ('APP_ROOT', '/resources/includes/header.html'); ?>
// Here I do not get any errors, but the header is not called either
<?php define 'APP_ROOT', '/resources/includes/header.html'; ?>
//Parse error: syntax error, unexpected ''APP_ROOT'' (T_CONSTANT_ENCAPSED_STRING) in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5

Adding php to html

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/

want to open a page in my current page with href when I click on a menu element [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a menu made with ul and li elements I use href to open a page when I click on one of the li , the problem is that I want to open the page that contains href in the same page in the main file, because I have a footer and a header.
A simple way to do it and without page refresh is to use AJAX technology and JS (+ just a bit of jQuery)
Search Engine friendly AJAX driven website:
BASIC EXAMPLE:
header.php
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>AJAX driven site - by Roko C.B. - TEST</title>
</head>
<body>
<?php include 'menu.html'; ?>
menu.html
<ul id="nav">
<li> HOME </li>
<li> FOO </li>
<li> BAR </li>
</ul>
footer.php
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
$(function(){ // DOM Ready (shorthand)
window.onpopstate = function(e) {
if(e.state){
$("#content").html( e.state.html );
document.title = e.state.pageTitle;
}
};
$('#nav a').click(function(e) {
e.preventDefault(); // prevent default anchor behavior
var URL = $(this).attr('href'); // get page URL
$('#page').html(''); // empty old HTML content.
// Target URL and get the #content element
// and put it into #page of this page
$('#page').load(URL +' #content', function(data){
// Load callback function.
// Everything here will be performed once the load is done.
// Put here whatever you need.
// ...
// Also, let's handle history and browser's AddressBar
var $data = $(data),
content = $data.find('#content').html(),
pageTitle = $data.find('h1').text();
window.history.pushState({"html":content, "pageTitle": pageTitle},"", URL );
});
});
});
</script>
</body>
</html>
Than all you need are your pages with the content:
index.php
<?php include 'header.php'; ?> <!-- header has menu.html -->
<div id="page">
<div id="content">
<h1>WELCOME!</h1>
<p>Article here...</p>
</div>
</div>
<?php include 'footer.php'; ?>
foo.php
<?php include 'header.php'; ?> <!-- header has menu.html -->
<div id="page">
<div id="content">
<h1>FOO!</h1>
<p>Foo Article here...</p>
</div>
</div>
<?php include 'footer.php'; ?>
bar.php
<?php include 'header.php'; ?> <!-- header has menu.html -->
<div id="page">
<div id="content">
<h1>BAR!</h1>
<p>Bar Article here...</p>
</div>
</div>
<?php include 'footer.php'; ?>
Documentation:
http://php.net/manual/en/function.include.php
http://api.jquery.com
http://api.jquery.com/load/
http://api.jquery.com/find/
http://api.jquery.com/html/
https://developer.mozilla.org/en-US/docs/Web/API/window.onpopstate
https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Manipulating_the_browser_history
What you need to do from reading you post is have the header and footer in their own separate files.
On all the pages include this header and footer where you want them, so when you open the new page up the header and footer will be the same across all the pages.
same for the menu. put it in its own file and include it in every page. then its always the same across every page and you only have to update one file.
#LazyBrain : then u just have to play around with id's.
for example:
<ul>
<li>Questions</li>
<li>Tags</li>
<li>Answers</li>
</ul>
<div id="questions">
....................
put your content for question page here
</div>
If you are using the target attribute within the href, take it out and you will open the link in the same window.
e.g.
Click Here - New window
Should be
Click Here - Current window
I believe this is what you are looking for, I've written a html page for you to demonstrate how you can use anchor tag to set your hyperlink reference(href) to the same page.
Try this
<html>
<body>
Go to footer
<div><a id="header">Your Header</a></div>
<div style="height:900px;"></div>
<div><a id="footer">Your Footer</a></div>
Go to Header
</body>
</html>
Update
Finally I got your problem, you want to use same footer and header on all your pages...Right??
Actually you are looking for a code that lets you use your already designed PHP files.
So you need just to use php include() function
Syntax:
Before your header section
<?php include 'header.php'; ?>
Before your footer section
<?php include 'footer.php'; ?>
Note:
You can also use <?php require 'header.php'; ?>
but this can generate an error in case your header and footer files are missing.

Javascript div hide not working

I am trying to hide a comment form on my wordpress blog (although the page isn't the wordpress blog, I just get the posts).
If I have comments then the hide/show will work for the form and for the comments. If I have no comments the function doesn't work and i'm not sure why.
If anybody can help I can upload the php files that show the posts (blog.php) and the comments page (comments.php) that is generated within the wordpress theme.
EDIT: PHP code removed as not relevant to error. Relevant HTML code as follows:
...
<body class="home blog logged-in custom-background">
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#content img").addClass("imageSeven");
});
</script>
...
<a id="replytitle" href="javascript:togglecommentform('replyform17');">Show Comment Form</a>
<div id="replyform17" style="display:block;">
...
</div>
...
<a id="replytitle" href="javascript:togglecommentform('replyform6');">Show Comment Form</a>
<div id="replyform6" style="display:block;">
...
</div>
...
You have a problem, in that the output (view source) has a reference to jQuery right at the top:
<body class="home blog logged-in custom-background">
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#content img").addClass("imageSeven");
});
</script>
Some points on this:
Because you don't include a reference to jQuery anywhere - this will cause an error, meaning that even if the rest of you JavaScript is valid, it will fail to run.
You don't need jQuery(document).ready... if you move all your JavaScript to the bottom of the page (just before the </body> end tag.)
Your main problem seems to be a confused code structure. Based on the messy code you have (no offense), I would recommend using a library like jQuery:
Step 1: Remove all the JavaScript you have in that page.
By the looks of things, that just means the <script> block thats right beneath your <body> tag.
Step 2: Replace these <a> start tags:
<a id="replytitle" href="javascript:togglecommentform('replyform17');">
<a id="replytitle" href="javascript:togglecommentform('replyform6');">
With these:
<a id="replytitle17" href="#">
<a id="replytitle6" href="#">
Step 3: Just before the </body> tag, include the following:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var images = $('#content img');
if (images.length > 0) { images.addClass("imageSeven"); }
$('#replytitle17').click(function() { $('#replyform17').toggle(); });
$('#replytitle6').click(function() { $('#replyform6').toggle(); });
</script>
This should achieve everything your page has, in jQuery.

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