Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

lil' help please

Featured Replies

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

  • 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...

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 }; ?>

  • 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?

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>

  • 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 :)

Not a problem... Always enjoy helping people learn. Just remember never to put <?php tags inside <?php tags!

  • Author

Ok cool - that's like PHP101 for me - first lessons and all that :p

 

Cheers

  • Author

Yes thanks - I have had a bit of a look at these. I will start re-watching them all though :good: cheers

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.