April 23, 200917 yr Probably simple.... BUT... I am using wordpress with a fully customised template. I have a little snippet of code which checks if a user is logged in and then echo's out wording based on if they are or not (see below) <?php if (is_user_logged_in()){ $varInc = "Search Goes Here"; echo "<div id='login-top'><div id='searchy'>$varInc</div></div>"; } else { $varInc = "Log In Goes Here"; echo "<div id='login-top'><div id='searchy'>$varInc</div></div>"; }; ?> This works PERFECTLY!! so where's the problem I hear you scream... well when I do this: <?php if (is_user_logged_in()){ $varInc = "<?php include (TEMPLATEPATH . '/searchform.php'); ?>"; echo "<div id='login-top'><div id='searchy'>$varInc</div></div>"; } else { $varInc = "Log In Goes Here"; echo "<div id='login-top'><div id='searchy'>$varInc</div></div>"; }; ?> and try to include the search template file then nothing shows up.... a little help would be much appreciated. Oh and if I run <?php include (TEMPLATEPATH . '/searchform.php'); ?> On its own then it displays the search perfectly... help help help Cheers guys
April 23, 200917 yr Author Oh and if it is any help... the source code is like this: <div id='login-top'><div id='searchy'><?php include (TEMPLATEPATH . '/searchform.php'); ?></div></div> Rather than parsing the php code...
April 23, 200917 yr Just a quick stab here, but couldn't you just close off your PHP and insert the html code instead of storing it as a variable, and echoing it? This is something to do with the variable type and in particular a string I'm sure a PHP expert could answer right, but just looking at it, this would work just as well if you made it thus: <?php if (is_user_logged_in()){ ?> <div id='login-top'><div id='searchy'><?php include (TEMPLATEPATH . '/searchform.php'); ?></div></div> <?php } else { ?> <div id='login-top'><div id='searchy'><!-- login content --></div></div> <?php }; ?>
April 23, 200917 yr Author No I have tried that wes mate - thanks for the suggestion, but as soon as I put the PHP in like that, the whole thing breaks down I did a google search and they seem to think variables are the way to go... but I am so stumped Any other ideas?
April 23, 200917 yr You've got PHP tags within PHP tags: <?php if (is_user_logged_in()){ $varInc = "<?php include (TEMPLATEPATH . '/searchform.php'); ?>"; echo "<div id='login-top'><div id='searchy'>$varInc</div></div>"; } else { $varInc = "Log In Goes Here"; echo "<div id='login-top'><div id='searchy'>$varInc</div></div>"; }; ?> Should be <?php if (is_user_logged_in()){ $varInc = TEMPLATEPATH . '/searchform.php'; echo "<div id='login-top'><div id='searchy'>"; include($varInc); echo "</div></div>"; } else { $varInc = "Log In Goes Here"; echo "<div id='login-top'><div id='searchy'>".$varInc."</div></div>"; }; ?> However that's quite in ifficient and can be shortened too: <div id="login-top"> <div id="searchy"> <?php if(is_user_logged_in()) { include(TEMPLATEPATH . '/searchform.php'); } else { echo "Log in Goes Here"; } ?> </div> </div>
April 23, 200917 yr Author It worked! Thank you Skidz. I really appreciate your help on this and your maturity in helping me out after our 'disagreement' the other day I am working hard to improve my development skills so I really appreciate your help
April 23, 200917 yr Not a problem... Always enjoy helping people learn. Just remember never to put <?php tags inside <?php tags!
April 23, 200917 yr If your still at an early stage of learning I suggest you take a look at the "diving into php" screencast series on Blog.Themeforest.net
April 23, 200917 yr Author Yes thanks - I have had a bit of a look at these. I will start re-watching them all though cheers
Create an account or sign in to comment