Document Name within a PHP include - php

I have 16 Documents with a php include in them to include a php template like this:
<?php include("templates/template.php"); ?>
Inside that template there is a little bit of PHP which finds the document name and prints it. The problem is that for the php document to be included its PHP is processed (Naturally because its PHP), this means that the document name finder is finding the name of the template and not the main document. What I am trying to do is have 16 PHP Files which act as a front end and are accessed by the User, these files include the Template file which finds the name of the accessed file and pulls html code from another file into the body of the template. This means that the content for the file is external to the Structure of the site and allows a level of simplicity for basic editing (I.E. The client can edit their website). As I stated above my method has a simple problem what I am trying to figure out is if anyway knows how to do this.The Template file is pasted below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.5.2.min.js" type="text/javascript">
</script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
<!--
var screenwidth = screen.width;
if (screenwidth < 1180){
document.write('<link rel="stylesheet" href="css/ldrop.css" type="text/css" media="screen" />');
}
else
{
document.write('<link rel="stylesheet" href="css/drop.css" type="text/css" media="screen" />');
}
// -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Alignment Courses</title>
<link rel="shortcut icon" href="favicon.png" />
</head>
<body onload="makerequest('templates/quote.php','quote'); return false;makerequest('editing/<?php echo basename(__FILE__, '.' . pathinfo(__FILE__, PATHINFO_EXTENSION)); ?>.php','main')">
<div id="menu"><img src="webpics/logo.png" width="225" height="150" onmouseover="this.src='webpics/logoinv.png'" onmouseout="this.src='webpics/logo.png'" style="float:left" alt="Exit To Banner"/>
<div id="logo"><a href="index.html"><img src="webpics/Yoga Health.png" alt="Yoga Health Townsville" width="458" height="43" vspace="20"
onmouseover="this.src='webpics/Yoga Health Inv.png'"
onmouseout="this.src='webpics/Yoga Health.png'"/></a>visit the photo gallery</div>
<div id="nav" class="mainmenu">
<ul>
<li class="menu1">Home</li>
<li class="menu2">Classes
<ul>
<li>Daily</li>
<li>Beginner</li>
<li>Alignment</li>
<li>Preparation</li>
</ul>
</li>
<li class="menu3">Family Yoga
<ul>
<li>Family Yoga</li>
<li>Childrens Yoga</li>
<li>Prenatal Yoga</li>
</ul>
</li>
<li class="menu4">Prices
<ul>
<li>Classes</li>
<li>Equipment</li>
</ul>
</li>
<li class="menu5">Events/Workshops
<ul>
<li>Dance</li>
</ul>
</li>
<li class="menu6">Our Teachers</li>
<li class="menu7">Location</li>
</ul>
</div></div>
<div id="content"><div id="sidebar"><div id="sidebar">
<p><strong class="MyriadPromain"><em>Contacts</em></strong><br />
<span class="MyriadProcontact">Shop 3, 262 Woolcock Street, Currajong, 4812 <br />
Information: info#yogahealth.net.au<br />
Bookings: bookings#yogahealth.net.au<br />
Phone: 07 47 751 154<br />
Mobile: 0410 085 054<br /><br /></span>
<span class="ArialGroup">For Enquiries Regarding Group Bookings<br />Click Here</span>
</p>
<p><img src="http://www.yogahealth.net.au/webpics/facebook.gif" width="120" height="45" /></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FYoga-Health-Townsville%2F140216156034239%23&layout=box_count&show_faces=false&width=700&action=like&font=verdana&colorscheme=light&height=50" scrolling="No" frameborder="0" style="border:none; overflow:hidden; width:65px; height:65px;" allowtransparency="true"></iframe>
<p>
Links to other Websites in our Community</p>
<div class="quoteback">
<img src="http://www.yogahealth.net.au/webpics/Refresh.gif" height="20px" width="20px" align="right" />
<div id="quote"><br \></div>
</div>
<br \>
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 6000,
width: 250,
height: 300,
theme: {
shell: {
background: '#333333',
color: '#ffffff'
},
tweets: {
background: '#000000',
color: '#ffffff',
links: '#4aed05'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
}
}).render().setUser('YogaHealth1').start();
</script>
<?php include("templates/quotein.php"); ?>
</div>
</div><div id="main"><?php include("editing/alignment.php"); ?></div></div>
<div id="footer"></div>
</body>
</html>
Many Thanks in advance.

Template should be a piece of code, which takes parameters and based on that generates output.
The solution for this problem could be, that in that accessed file, you declare a variable with appropriate name and pass it to the template. There you will have each page differentiated as requested.
Solution:
Magic constant __FILE__ holds name of the included file, if used in include. So the solution is to move php code to the file, from which you are running the include.

Related

Why is there PHP/HTML code at the end of my .sql file?

I'm trying to move a website from one host to another. Everything is going great except there is HTML code at the end of every db dump I do (via phpmyadmin. The site is leaving GoDaddy.) As a result, I cannot import the .sql file to a database on DigitalOcean. If I remove the code, the dump works but the site doesn't. Also, I did not create the site. I'm just moving it.
Here's what's at the end of the .sql file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
<title>phpMyAdmin</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="phpmyadmin.css.php?token=a265dc411b059a3932a26eeefe2fc8f0&js_frame=right&nocache=4099247312" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
<script type="text/javascript">
try {
// can't access this if on a different domain
var topdomain = top.document.domain;
// double-check just for sure
if (topdomain != self.document.domain) {
alert("Redirecting...");
top.location.replace(self.document.URL.substring(0, self.document.URL.lastIndexOf("/")+1));
}
}
catch(e) {
alert("Redirecting... (error: " + e);
top.location.replace(self.document.URL.substring(0, self.document.URL.lastIndexOf("/")+1));
}
</script>
<script type="text/javascript">
// <![CDATA[
// Updates the title of the frameset if possible (ns4 does not allow this)
if (typeof(parent.document) != 'undefined' && typeof(parent.document) != 'unknown'
&& typeof(parent.document.title) == 'string') {
parent.document.title = '68.178.217.9 / newdbgcf / merchant';
}
// ]]>
</script>
<script src="./js/tooltip.js" type="text/javascript"></script>
<meta name="OBGZip" content="true" />
<!--[if IE 6]>
<style type="text/css">
/* <![CDATA[ */
html {
overflow-y: scroll;
}
/* ]]> */
</style>
<![endif]-->
</head>
<body>
<div id="TooltipContainer" onmouseover="holdTooltip();" onmouseout="swapTooltip('default');"></div>
<div id="serverinfo">
<a href="main.php?token=a265dc411b059a3932a26eeefe2fc8f0" class="item"> <img class="icon" src="./themes/original/img/s_host.png" width="16" height="16" alt="" />
Server: 68.178.217.9</a>
<span class="separator"><img class="icon" src="./themes/original/img/item_ltr.png" width="5" height="9" alt="-" /></span>
<a href="db_structure.php?db=newdbgcf&token=a265dc411b059a3932a26eeefe2fc8f0" class="item"> <img class="icon" src="./themes/original/img/s_db.png" width="16" height="16" alt="" />
Database: newdbgcf</a>
<!-- PMA-SQL-ERROR -->
<div class="error"><h1>Error</h1>
<p><strong>SQL query:</strong>
<img class="icon" src=" ./themes/original/img/b_edit.png" width="16" height="16" alt="Edit" /> </p>
<p>
<span class="syntax"><span class="syntax_alpha syntax_alpha_reservedWord">SHOW</span> <span class="syntax_alpha syntax_alpha_reservedWord">TABLE</span> <span class="syntax_alpha syntax_alpha_reservedWord">STATUS</span> <span class="syntax_alpha syntax_alpha_reservedWord">LIKE</span> <span class="syntax_quote syntax_quote_single">'merchant'</span><span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span>
</p>
<p>
<strong>MySQL said: </strong><img class="icon" src="./themes/original/img/b_help.png" width="11" height="11" alt="Documentation" title="Documentation" />
</p>
<code>
#2006 - MySQL server has gone away
</code><br />
</div><fieldset class="tblFooters"> </fieldset>
<script type="text/javascript">
//<![CDATA[
// updates current settings
if (window.parent.setAll) {
window.parent.setAll('en-utf-8', 'utf8_unicode_ci', '1', 'newdbgcf', 'merchant', 'a265dc411b059a3932a26eeefe2fc8f0');
}
// set current db, table and sql query in the querywindow
if (window.parent.reload_querywindow) {
window.parent.reload_querywindow(
'newdbgcf',
'merchant',
'');
}
if (window.parent.frame_content) {
// reset content frame name, as querywindow needs to set a unique name
// before submitting form data, and navigation frame needs the original name
if (typeof(window.parent.frame_content.name) != 'undefined'
&& window.parent.frame_content.name != 'frame_content') {
window.parent.frame_content.name = 'frame_content';
}
if (typeof(window.parent.frame_content.id) != 'undefined'
&& window.parent.frame_content.id != 'frame_content') {
window.parent.frame_content.id = 'frame_content';
}
//window.parent.frame_content.setAttribute('name', 'frame_content');
//window.parent.frame_content.setAttribute('id', 'frame_content');
}
//]]>
</script>
</body>
</html>
This comes after a very number of "INSERT INTO" commands. The last of which is no different than the rest.
There is probably an error that occured while exporting the database. You can either put that HTML-Code into a text file (.html) and open it with your browser to see what it contains or just go through the code.
You will find these lines in the code:
<strong>MySQL said: </strong><img class="icon" src="./themes/original/img/b_help.png" width="11" height="11" alt="Documentation" title="Documentation" />
</p>
<code>
#2006 - MySQL server has gone away
</code>
You now have your error message. Google it, search for it on stackoverflow, etc.
Maybe this helps as well:
MySQL Server has gone away when importing large sql file
It's about importing not exporting, but it should be the same problem...

Linking to a static page

I am a complete Yii newbie so please forgive a simple question. I've been reading up on various posts and can't find anything that works. All I'm trying to do is setup a Yii site (which I've done) and then link to a static page using my Main layout.
Below are the three files I think are relevant:
index.php: the view I show on my homepage as content with the main layout
terms_of_use.php: the view I'm unsuccessfully trying to get to appear in the main layout
main.php: my master layout
Within the footer of the main layout, the link to the static page is:
Terms of Use
When I click on it, it generates what I think is the correct url in the brower address bar:
http://localhost/Company/index.php?r=site/page&view=terms_of_use
but what gets shown is the content of index.php, not terms_of_use.php. I'm using the default SiteController. Is there something special about index.php I don't know about, or am I doing something else dumb? Thanks for any help.
views/site/index.php:
<?php
/* #var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<div id="content" class = "clearfix">
<div class="threeColBlock">
<div class="padded">
<h2 class="pageTitle">Heading 1</h2>
<p>Blurb 1</p>
</div>
</div>
<div class="threeColBlock">
<div class="padded">
<h2 class="pageTitle">Heading 2</h2>
<p>Blurb 2</p>
</div>
</div>
<div class="threeColBlock">
<div class="padded">
<h2 class="pageTitle">Heading 3</h2>
<p>Blurb 3</p>
</div>
</div>
</div>
views/site/pages/terms_of_use.php:
<?php
/* #var $this SiteController */
$this->pageTitle=Yii::app()->name . ' - About';
$this->breadcrumbs=array(
'About',
);
?>
<div id="content" class = "clearfix">
<h2 class="pageTitle">Terms of Use</h2>
<div class = "smallText">
<p>
Some legal junk
</p>
</div>
</div>
views/layouts/views/main.php:
<?php /* #var $this Controller */ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/marketing.css">
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/cssmenu.css" media="screen" />
<title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>
<body>
<div id="header" class="clearfix">
<div id="logo"><image src="images/logo,56x38,trans(white).gif"></div>
<div id="logoName">Company</div>
<div id="topRight">Bla bla bla</b></div>
</div>
<!-- Menu -->
<div id='cssmenu'>
<ul>
<li class='active'><a href='dummy.com'><span>home</span></a></li>
<li class='has-sub'><a href='#'><span>products</span></a>
<ul>
<li><a href='dummy.com'><span>prod1</span></a></li>
<li><a href='dummy.com'><span>prod2</span></a></li>
<li class='last'><a href='dummy.com'><span>prod3</span></a></li>
</ul>
</li>
<li><a href='dummy.com'><span>about</span></a></li>
<li class='last'><a href='dummy.com'><span>contact</span></a></li>
</ul>
</div>
<div id="mainImageContainer">
<div id="mainImage">
<image src = "images/main_image.jpg">
</div>
</div>
<?php echo $content; ?>
</div><!-- page -->
<div id="footer">
Copyright &copy 2011 Company. All rights reserved. | Terms of Use
</div>
</body>
</body>
</html>
Found it. I had enabled the urlManager in config/main.php. If I change my original link to the following then I get what I want.
http://localhost/Company/index.php/site/page/view/terms_of_use
In regards to your specific question, I believe you may have forgotten the step of overriding the actions() method in the default site controller - though that raises the question: Which version of the Yii framework are you using? The override is already included in Yii 1.1.12.
Also, as per the comments on that yii wiki article:
If you happen to use accessRules, don't forget to add 'page' (or
whatever name you have in) to allowed action as well.
http://www.yiiframework.com/wiki/22/how-to-display-static-pages-in-yii/ is a great post on using static pages in Yii, the bulk of it:
First, in the default SiteController (or other controller if you
like), override the actions() method as follows,
public function actions()
{
return array(
'page'=>array(
'class'=>'CViewAction',
),
);
}
Second, create a folder protected/views/site/pages.
Third, save each static page as a PHP file under this folder. For
example, we can save the "about this site" page as about.php. Note,
these pages will use the application's default layout. Therefore, only
the main content needs to be saved in each file.
We are done! To access a static page, e.g., the about page, we can use
the following URL:
http://www.example.com/index.php?r=site/page&view=about
Try not to hardcode urls, instead use functions like createUrl, (there are other variants of it).
When you hardcode urls the problem you faced could arise, createUrl takes into account your urlManager configuration, and generates a url accordingly, so when you make changes you don't have to go to every view and change the url again.
You can use it like so:
About
Or use CHtml::link:
echo CHtml::link('About',array('/site/page', 'view'=>'temrs_of_use'));

Error in header.php broke my WP site?

I somehow managed to blow my Wordpress Site up; The last file I was in was my header.php, I've been combing through it for a couple hours and haven't found whats causing the break yet.
Any suggestions:
Header.php below:
<?php
/**
* #package WordPress
* #subpackage Default_Theme
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?> >
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>"/>
<meta property="fb:admins" content="1641586359" />
<title>
<?php
if($pagePtr =="home"){
print"Read It Forward";
}else if( is_search() ){
echo the_search_query(); print" - Read It Forward Search Results";
}else{
wp_title('', true, 'left');
} ?>
<?php //bloginfo('name'); ?>
</title>
<meta name="description" content="Sneak peeks at great reads, behind-the-scenes insights from authors, lively & provocative reader's guides & fabulous free books." />
<link type="text/css" href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet" />
<link rel="shortcut icon" href="<?php bloginfo('template_directory'); ?>/images/rif_icon.gif" />
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if (is_single()) { ?>
<meta property="og:title" content="<?php single_post_title(''); ?>" />
<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php
if($image= get_post_meta($post->ID, "image", true)) { echo $image; }
else if($isbn= get_post_meta($post->ID, "isbn", true)) { ?>http://www.randomhouse.com/images/dyn/cover/?source=<?php echo $isbn; ?>&height=225&maxwidth=150<?php }
else { ?>
http://www.crownpublishing.com/images/readitforward/rif_square.jpg
<?php }?>" />
<?php } ?>
<link href="<?php bloginfo('template_directory'); ?>/tweet/tweet.css" media="all" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.crownpublishing.com/js/jquery.hoverIntent.minified.js"></script>
<script language="javascript" src="<?php bloginfo('template_directory'); ?>/tweet/jquery.tweet.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript" src="http://www.randomhouse.com/js/emv.js"></script>
<script language="javascript" src="<?php bloginfo('template_directory'); ?>/includes/RIFvalid.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js" ></script>
<!--[if IE]>
<style>
.searchfield {
position:relative;
top:-1px;
}
</style>
<![endif]-->
</head>
<body>
<div id="BGcontainer">
<div id="container">
<div align="center" style="width:100%; background:#FFF;"><img src="<?php bloginfo('template_directory'); ?>/images/readitforward_ad.jpg" style="max-width:700px; border: 15px solid white"/></div>
<div id="header">
<div id="title">
<img src="http://www.osmproduction.com/RIF/wp-content/uploads/2012/02/NewRIF_logo.gif" border="0" alt="Read It Forward"><br />
<p>Sneak peeks at great reads, behind-the-scenes insights from authors, lively and provocative reader's guides, and fabulous free books</p>
<div class="clear"></div>
</div>
<div id="Hsocial">
<div id="Hscontainer">
<div class="clear"></div>
<a class="SCRIBDbutton buttonHover" href="http://www.scribd.com/document_collections/2697109"></a>
<a class="GRbutton buttonHover" href="http://www.goodreads.com/user/show/3313709"></a>
<a class="FBbutton buttonHover" href="http://www.facebook.com/ReadItForward"></a>
<a class="TWbutton buttonHover" href="http://twitter.com/readitforward"></a>
<a class="YTbutton buttonHover" href="http://www.youtube.com/user/crownbooks#g/c/CBA6E62882B7B93F"></a>
<a class="RSSbutton buttonHover" href="<?php bloginfo('rss2_url'); ?>"></a>
<div class="clear"></div>
<?php
if( function_exists('FA_display_slider') ){
FA_display_slider(64);
}
?>
</div>
</div>
<div id="searchBox">
<?php get_search_form(); ?>
</div>
<?php //MENU: http://spyrestudios.com/how-to-create-a-sexy-vertical-sliding-panel-using-jquery-and-css3/ ?>
<?php //SLIDEIN tab: http://spyrestudios.com/how-to-create-a-sexy-vertical-sliding-panel-using-jquery-and-css3/ ?>
</div>
</div>
<div align="center">
<ul id="nav" align="center">
<li class="navItem"><p class="navInfo">FREE BOOKS</p></li>
<li class="navItem"><p class="navInfo">READER REVIEWS</p></li>
<li class="navItem"><p class="navInfo">MEET THE AUTHOR</p></li>
<li class="navItem"><p class="navInfo">MEET THE EDITOR</p></li>
<li class="navItem"><p class="navInfo">BOOK GROUPS</p></li>
<li class="navItem"><p class="navInfo">FAVORITES</p></li>
<li class="navItemLast navMenu">
<p class="navInfo">ALL CATEGORIES</p>
<div align="left">
<ul class="subNavMenu">
<li><div class="subNavItem">Book Groups</div></li>
<li><div class="subNavItem">Critics Rave</div></li>
<li><div class="subNavItem">Enthusiasms</div></li>
<li><div class="subNavItem">Free Books</div></li>
<li><div class="subNavItem">Gift Guide</div></li> <li><div class="subNavItem">Living with Books</div></li>
<li><div class="subNavItem">Meet the Author</div></li>
<li><div class="subNavItem">Meet the Editor</div></li>
<li><div class="subNavItem">Reader Reviews</div></li>
<?php //wp_list_categories('orderby=name&include=3343'); ?>
</ul>
</div>
</li>
<?php /*
<li class="navItemLast navMenu"><p class="navInfo">RECENT ISSUES</p>
<ul class="subNavMenu">
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
</ul>
</li>
*/?>
<?php //MENU: http://spyrestudios.com/how-to-create-a-sexy-vertical-sliding-panel-using-jquery-and-css3/ ?>
<?php //SLIDEIN tab: http://spyrestudios.com/how-to-create-a-sexy-vertical-sliding-panel-using-jquery-and-css3/ ?>
</ul>
</div>
</div>
<script>
$('.navItem').click(function() {
var newLink = $('a:first-child',this).attr("href");
if(newLink != "" && newLink != "#") {
window.location =newLink;
}
return false;
});
</script>
<script>
$('.navItem').click(function() {
var newLink = $('a:first-child',this).attr("href");
if(newLink != "" && newLink != "#") {
window.location =newLink;
}
return false;
});
</script>
UPDATE: Is there an app anywhere online to run tests for errors? I think it may be a missing closing tag somewhere, though I haven't spotted it. I've ran syntax tests against PHP 4+ on a site I found, and appears I'm OK there.
Try turning debugging on.
http://codex.wordpress.org/Editing_wp-config.php#Configure_Error_Log
This should give you an idea of where to start. Otherwise comment out all the php code on the page. Then uncomment them line by line until you find out what causes your page to break. This is where your syntax error will be.
Also, it is a bit unclear what blow up is. It doesn't work at all? Or it works, but the page isn't displaying properly? The former case will be a php error, the latter likely a closing tag issue.

Align image img with text in box

EDIT: This works now thanks to ' olly_uk '
EDIT2: It works now, but the alignment of the boxes is wrong. You can view a screenshot HERE. Without any text it will align perfectly with 2 boxes on each line at a perfect distance from each other, but with text it echo's it under each other. Why?
I am trying to echo a image, then in that image I want to echo text from a database.
Well it echo's the images (3, because I only have 3 product examples in the database), but the products are not aligned in the boxes. It comes under it. I have searched on google but could not find anything
Is it even possible to use e.g. margin-top to move the posted echo so I could align it in the box?
I want to use style or class in the PHP...
Example image: IMAGE
adding <style>p{...};h3{...};</style> worked
Code sample
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BOX</title>
<link href="includes/style.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
<style>
p {
position:relative;
top:-240px;
left:180px;
}
h3 {
position:relative;
top:-270px;
left:30px;
}
</style>
</head>
<?php
include 'includes/connection.php';
$query = "SELECT * FROM products";
$result = mysql_query($query);
?>
<body>
<div class="header navpos c1" id="nav">
<table summary="header" border="0">
<tr>
<td>
<ul>
<li class="home"></li>
</ul>
</td>
<td>
<ul>
<li class="about"></li>
</ul>
</td>
<td>
<ul>
<li class="contact"></li>
</ul>
</td>
<td>
<ul>
<li class="twitter"><img src="includes/images/f_logo.png" alt="** PLEASE DESCRIBE THIS IMAGE **" /></li>
</ul>
</td>
<td>
<ul>
<li class="facebook"><img src="includes/images/t_logo.png" alt="link to Syndicate Plus Twitter" /></li>
</ul>
</td>
</tr>
</table>
</div>
<div class="offers">
<div class="content_box">
<?php
while($products = mysql_fetch_array($result)) {
echo '<img src="includes/images/content_box.png" border=0 />';
echo "<h3>" . $products['products'] . "</h3>";
echo "<p>" . $products['description'] . "</p>";
}
?>
</div>
</div>
</body>
</html>
i think you could achieve this using CSS. by having a negative top to bump the text over the top of the image. will try to give some example code when i get home.
check this out in the mean time, w3schools CSS-positioning
hope that helped
EDIT: added code to show what i mean
<html>
<head>
<title>text over image</title>
<style>
p {
position:relative;
top:-200px;
}
h2 {
position:relative;
top:-140px;
}
</style>
<head>
<body>
<img src="/images/office1.jpg" alt="demo image"/>
<h2>test text</h2>
<p>test desciption text</p>
<hr/>
<img src="/images/office1.jpg" alt="demo image"/>
<h2>test text</h2>
<p>test desciption text</p>
</body>

Using php variables to manipulate the html's title and the body's Id (is anybody doing this?)

I basically use php variables to store the value of the title and the body's ID.
This last one is a technique to have my button (pressed) in the navigation according to which section of the page the user is (in this case the user will know he is currently at "home").
Beginning of my index.php:
<?php
$title = "New Project";
$body = "home";
include("common/header.php");
?>
<div id="content">
<div class="container">
<div id="tagline">
Beginning of my header.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="styles/slimbox2.css" />
<link rel="stylesheet" type="text/css" href="styles/global.css" />
<link rel="stylesheet" type="text/css" href="styles/home.css" />
<link rel="stylesheet" type="text/css" href="styles/contact.css" />
<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="scripts/jquery.corner.js"></script>
<script type="text/javascript" src="scripts/jquery.validate.js"></script>
<script type="text/javascript" src="scripts/slimbox2.js"></script>
<script type="text/javascript" src="scripts/custom.js"></script>
</head>
</head>
<body id="<?php echo $body; ?>">
<div id="header">
<div class="container">
<div id="topbar">
<h1>wider design</h1>
<ul id="lang">
<li>English</li>
<li>Español</li>
<li>中文(繁體)</li>
<li>中文(简体)</li>
</ul>
<ul id="nav">
<li class="home">home</li>
<li class="products">products</li>
<li class="about">about</li>
<li class="contact">contact</li>
</ul>
To let the user know in which section he/she is:
#home li.home a, #products li.products a, #contact li.contact {
color: #999;
}
is there a simpler way of doing this?
Am I using unnecessary those PHP variables?
Yes, what you're doing is fine. I do something similar with a PageTemplate class. In addition to setting the title and navigation, it allows navigation links to appear based on user authentication, allows javascript and css to be added to the head section, etc.
What you're doing is very common. There are a million ways to do it, but they'll all require setting some variables.
janoChen,
I use the following method:
// get the url
$url= $_SERVER['PHP_SELF'];
// add a class on the menu item
<ul id="lang">
<li><a href="index.php" <?php if (strpos($url, "index.php")) { echo " class='active'"; } ?>>English</a></li>
//with css I set a style for the class active
li a.active {
color: #990000;
}
But you method also works.
Or else use an MVC framework like CakePHP
This works, but you should consider using a template engine such as Smarty instead.

Categories