WatsonN Posted May 17, 2010 Share Posted May 17, 2010 What I am trying to do is setup a static theme page and the title just call a variable. So in order to do this I need to figure out how to make ($FooTitle == $title) I know the echo in the code below isnt right either but its all I could come up with to make it fail... <?php if ($url == $s1) { echo($AIWTDtitle == $title) ; } elseif ($url == $s2) { echo($LMtitle == $title); } elseif ($url == $s3) { echo($TMLtitle == $title); } elseif ($url == 'home') { echo($HOMEtitle == $title); } ?> Thanks in advanced (: Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/ Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 One "=" for assignment, two "==" for comparison, so <?php if ($url == $s1) { $AIWTDtitle =$title ; } elseif ($url == $s2) { $LMtitle = $title; } elseif ($url == $s3) { $TMLtitle = $title; } elseif ($url == 'home') { $HOMEtitle = $title; } ?> But, this would make more sense: <?php if ($url == $s1) { $title = $AIWTDtitle; } elseif ($url == $s2) { $title = $LMtitle; } elseif ($url == $s3) { $title = $TMLtitle; } elseif ($url == 'home') { $title = $HOMEtitle; } echo $title; ?> Ken Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059291 Share on other sites More sharing options...
WatsonN Posted May 17, 2010 Author Share Posted May 17, 2010 Thank you. But when i tried that I could not get it to set a title. My index file looks like this: <?php require('variables.php') ?> <?php require('Header.php') ?> <?php require('Top.php') ?> <?php $url = (isset($_GET['p']) ? $_GET['p'] : home); ?> <?php if ($url == $s1) { include($l1); } elseif ($url == $s2) { include($l2); } elseif ($url == $s3) { include($l3); } else { include($home); } ?> <?php require('Bottom.php') ?> title:<?php echo $title; ?> The title script is in the var file. I tried it in the index file too and it wouldn't work there either. I put the echo at the bottom to see if that would return anything either and it didn't. Is this possible? Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059297 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 Can you show is the code for your include files? I don't see where you're using the variable. Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059300 Share on other sites More sharing options...
WatsonN Posted May 17, 2010 Author Share Posted May 17, 2010 Sure thing variables.php <?php $s1 = "AIWTD-Sugarland" ; $s2 = "LM-MontgomeryGentry" ; $s3 = "TML-JeremyCamp" ; $home = "home.php" ; $l1 = "Lyrics/Sugarland/All-I-Want-To-Do.php" ; $l2 = "Lyrics/Montgomery-Gentry/Lucky-Man.php" ; $l3 = "Lyrics/Jeremy-Camp/Take-My-Life.php" ; $AIWTDtitle = "All I Want To Do - Sugarland ~ Nathan Watson" ; $LMtitle = "Lucky Man - Montgomery Gentry ~ Nathan Watson" ; $TMLtitle = "Take My Life - Jeremy Camp ~ Nathan Watson" ; $HOMEtitle = "Welcome ~ Nathan Watson" ?> <?php if ($url == $s1) { $title = $AIWTDtitle; } elseif ($url == $s2) { $title = $LMtitle; } elseif ($url == $s3) { $title = $TMLtitle; } elseif ($url == 'home') { $title = $HOMEtitle; } echo $title; ?> Header.php <!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> <script language="Javascript" type="text/javascript" src="ajax.js"></script> <script type='text/javascript' src='http://watsonn.com/openx/www/delivery/spcjs.php?id=1'></script> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <?php echo "<title> ".$title." </title>"; ?> <meta name="OffLimits" content="" /> <link href="/default.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> Top.php <a name="top"> <!-- start header --> <?php include $_SERVER['DOCUMENT_ROOT'] . '/menu.php'; ?> <!-- end header --> <div id="header"> <div id="logo"> <h1><a href="#">NathanWatson</a></h1> <p>The OFFICIAL home page</p> </div> <div id="splash"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/twitter.php'; ?> </div> </div> <div id="wrapper"> <!-- start page --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <!-- start content --> <div id="content"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/song.php'; ?> <!-- <?php include("var.php"); ?> --> <div class="post"> <a name="post1"> Bottom.php </div> </div> <!-- end content --> <!-- start sidebars --> <?php include('sidebar1.php'); ?> <?php include $_SERVER['DOCUMENT_ROOT'] . '/sidebar2.php'; ?> <!-- end sidebars --> <div style="clear: both;"> </div> </div> </div> </div> <?php include $_SERVER['DOCUMENT_ROOT'] . '/quotes.php'; ?> <!-- end page --> </div> <div id="footer"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/footer.php'; ?> </div> <a name="bottom"> </body> </html> The page where this is implemented is http://WatsonN.com/Lyrics/ Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059303 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 Where is the varialble $url being set? If that's not set, then the variable $title will not be set. Ken Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059317 Share on other sites More sharing options...
WatsonN Posted May 17, 2010 Author Share Posted May 17, 2010 $url is being set in the index file <?php $url = (isset($_GET['p']) ? $_GET['p'] : home); ?> Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059320 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 But you're setting the $title in variables.php which is included before that line is executed. Also, the line should be <?php $url = (isset($_GET['p']) ? $_GET['p'] : 'home'); ?> Ken Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059321 Share on other sites More sharing options...
WatsonN Posted May 17, 2010 Author Share Posted May 17, 2010 I knew there was going to be something little like that that I missed. the new code: <?php $url = (isset($_GET['p']) ? $_GET['p'] : 'home'); ?> <?php require('variables.php') ?> <?php require('Header.php') ?> <?php require('Top.php') ?> <?php if ($url == $s1) { include($l1); } elseif ($url == $s2) { include($l2); } elseif ($url == $s3) { include($l3); } else { include($home); } ?> <?php require('Bottom.php') ?> Thank you very much Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059322 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 You don't have keep going in & out of PHP: <?php $url = (isset($_GET['p']) ? $_GET['p'] : 'home'); require('variables.php'); require('Header.php'); require('Top.php'); if ($url == $s1) { include($l1); } elseif ($url == $s2) { include($l2); } elseif ($url == $s3) { include($l3); } else { include($home); } require('Bottom.php'); ?> Ken Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059326 Share on other sites More sharing options...
WatsonN Posted May 17, 2010 Author Share Posted May 17, 2010 Diffrent writing styles Thank ya I'll use that one Link to comment https://forums.phpfreaks.com/topic/201996-title-vars-and-elseif/#findComment-1059335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.