Jump to content

case break (or switch)


attila2452

Recommended Posts

here is my php for pages (inside my index)

	<?php		if(isset($_GET["page"]) && $_GET["page"] != "home"){			if(file_exists($_GET["page"].".php")){				include($_GET["page"].".php");			}else{				include("PageNotFound.php");				}		}else{			include("home.php");		}	?>

here's my Title in my HTML

<title>Attila Hajzer | <?php include('title'); ?></title>

and here is my title.php

<?phpif $_GET["page"] == "about");  echo "About";else  echo "home";?>

how would i make this possible.here is a link to my websitehttp://attilahajzer.host-ed.net/

Link to comment
Share on other sites

your code looks very familar? to a similar topic i delt with where i use a swtch to add title and meta tags

	<?php		if(isset($_GET["page"]) && $_GET["page"] != "home"){			if(file_exists($_GET["page"].".php")){				include($_GET["page"].".php");		$pagelink = $_GET['page'];				switch ($pagelink)			{			case "gallery":				$title='This is gallery page';				$meta_description = 'This is my gallery page with image i have gathered blah, blah , blah';				$meta_keywords = 'gallery, images, of whatever';			break;			case "another":				$title='This is another page';				$meta_description = 'This is another page blah, blah , blah';				$meta_keywords = 'another page, of whatever';				break;				}			echo '<title>'.$title.'</title>'."\n";			echo '<meta name="description" content="'.$meta_description.'" />'."\n";			echo '<meta name="keywords" content="'.$meta_keywords.'" />'."\n";			}else{				include("PageNotFound.php");				}		}else{			include("home.php");		}	?>

Link to comment
Share on other sites

Alright so here is my entire INDEX.PHP file updated. i kept the title tag empty as default.for some reason the title page aspect of it is not responsive. it just shows the website url. howcome its not working properly, how can i fix this. and also thank you very much for helping me out with this. im learning.

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><link rel="stylesheet" href="style.css" type="text/css"/><style>sfHover = function() {	var sfEls = document.getElementById("main-navigation").getElementsByTagName("li");	for (var i=0; i<sfEls.length; i++) {		sfEls[i].onmouseover=function() {			this.className+=" hover";		}		sfEls[i].onmouseout=function() {			this.className=this.className.replace(new RegExp(" hover\\b"), "");		}	}}if (window.attachEvent) window.attachEvent("onload", sfHover);</style></head><body><div id="wrapper">	<div id="header">		<h1><a href="/">Attila Hajzer * </a></h1> 				<div id="main-navigation">			<?php include ('navigation.php'); ?>		</div>	</div>	<br />	<br />	<div id="main-content">	<?php		if(isset($_GET["page"]) && $_GET["page"] != "home"){			if(file_exists($_GET["page"].".php")){				include($_GET["page"].".php");		$pagelink = $_GET['page'];				switch ($pagelink)			{			case "home":				$title='Attila Hajzer | Home';				$meta_description = 'Welcome to my portfolio';				$meta_keywords = 'Welcome, home, Attila Hajzer, Attila, Hajzer, web, design, webdesign, web-design, web design';				break;  			case "about":				$title='Attila Hajzer | About';				$meta_description = 'This is my gallery page with image I have gathered blah, blah , blah';				$meta_keywords = 'about, Attila Hajzer, about Attila Hajzer';			break;			case "portfolio":				$title='Attila Hajzer | Portfolio';				$meta_description = 'This is my Portfolio page with image I have gathered blah, blah , blah';				$meta_keywords = 'Portfolio, Webdesign';				break;			case "another":				$title='Attila Hajzer | Contact';				$meta_description = 'This is my contact page where you can reach me via email.';				$meta_keywords = 'Contact Attila Hajzer';				break;			}			echo '<title>'.$title.'</title>'."\n";			echo '<meta name="description" content="'.$meta_description.'" />'."\n";			echo '<meta name="keywords" content="'.$meta_keywords.'" />'."\n";			}else{				include("PageNotFound.php");				}		}else{			include("home.php");		}	?>			</div>	<div class="clear"></div>		<div id="foot">				<div id="footer">			<ul>				<li><a href="#">Home</a></li>				<li><a href="#">About</a></li>				<li><a href="#">Portfolio</a></li>				<li><a href="#">Contact</a></li>			</ul>		</div>				<div id="copyright">© Copyright Attila Hajzer, 2010-2011. All Rights Reserved.</div></div></div></body></html>

Link to comment
Share on other sites

Ok! your setup is different from the topic i was referring to. the home title etc won't show because of first if condition, so it will have to be placed in the else if section, and you have remove this title code and place in head of your index.php document

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><?php		$title='';		 $meta_description = '';		 $meta_keywords = '';		if(isset($_GET["page"]) && $_GET["page"] != "home"){			if(file_exists($_GET["page"].".php")){		$pagelink = $_GET['page'];				switch ($pagelink)			{			case "about":				$title='Attila Hajzer | About';				$meta_description = 'This is my gallery page with image I have gathered blah, blah , blah';				$meta_keywords = 'about, Attila Hajzer, about Attila Hajzer';			break;			case "portfolio":				$title='Attila Hajzer | Portfolio';				$meta_description = 'This is my Portfolio page with image I have gathered blah, blah , blah';				$meta_keywords = 'Portfolio, Webdesign';				break;			case "another":				$title='Attila Hajzer | Contact';				$meta_description = 'This is my contact page where you can reach me via email.';				$meta_keywords = 'Contact Attila Hajzer';				break;			}			}else{		// page not found title			 $title='<title>Page Not Found</title>';				}		}else{				//home page title and meta tags		$title='Attila Hajzer | Home';				$meta_description = 'Welcome to my portfolio';				$meta_keywords = 'Welcome, home, Attila Hajzer, Attila, Hajzer, web, design, webdesign, web-design, web design';					}echo '<title>'.$title.'</title>'."\n";if($meta_description!=''){			 echo '<meta name="description" content="'.$meta_description.'" />'."\n";}if($meta_keywords!='') {			 echo '<meta name="keywords" content="'.$meta_keywords.'" />'."\n";}	?><link rel="stylesheet" href="style.css" type="text/css"/><style>sfHover = function() {	var sfEls = document.getElementById("main-navigation").getElementsByTagName("li");	for (var i=0; i<sfEls.length; i++) {		sfEls[i].onmouseover=function() {			this.className+=" hover";		}		sfEls[i].onmouseout=function() {			this.className=this.className.replace(new RegExp(" hover\\b"), "");		}	}}if (window.attachEvent) window.attachEvent("onload", sfHover);</style></head>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...