Jump to content

Need help with if/then statement


sc123

Recommended Posts

This is going to be very basic, but I can't figure it out!  With the following code I'm simply trying to use "code A" if the user is anywhere under the /wp directory (Wordpress) and "code B" if they aren't.  If anyone has suggestions on how to make this code work or make it better please feel free!

 

<?php if ($path == "http://www.sitename.com/wp") : ?>

<?php 
  define('WP_USE_THEMES', false);   
?>

<?php else : ?>

<?php 
  define('WP_USE_THEMES', false);
  require('./wp/wp-blog-header.php');   
?>

<?php endif; ?>

Link to comment
Share on other sites

<?php 
  if ($path == "http://www.sitename.com/wp") 
   {
      define('WP_USE_THEMES', false);   
   }
   else
   {
     define('WP_USE_THEMES', false);
     require('./wp/wp-blog-header.php');   
   }
?>

Link to comment
Share on other sites

Your code is much cleaner, thanks!  It didn't work though as it still causes problems when browsing the wordpress part of the site.  For example, if I use the following code:

 

     define('WP_USE_THEMES', false);
     require('./wp/wp-blog-header.php');   

 

...the rest of the site works as intended, but if I want to use the /wp part of the site correctly I can only use the following code:

 

      define('WP_USE_THEMES', false);   

 

The if/then statement would seem to perform this task, but for some reason it doesn't.

Link to comment
Share on other sites

I don't know if I'd use strcmp.  I'd be more inclined to go with egregi.

 

www.php.net/eregi

 

But for reference purposes, you can find info on strcmp here:

 

www.php.net/strcmp

 

EDIT:  I almost forgot to say WHY I'd use eregi instead.  With strcmp, the two strings have to be EXACTLY the same.  What happens if the user types in "www.sitename.com/wp" or "HTTP://WWW.SITENAME.COM/wp"? or some other variation?  you can deal with that using eregi.

Link to comment
Share on other sites

You're right in that they often won't be the same - also, what if there are looking at a WP post, then the path would be ./wp/?p=#.  That's why I need something that can handle everything below the /wp dir.  How could I use eregi to do that with this if/then?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.