Certis Posted August 4, 2010 Share Posted August 4, 2010 Hopefully people here know an easy solution to a problem I'm having. First of all, I'm using a script in Wordpress to retrieve the current url. Then I use a code in a link, adding a little code after it, which would switch the theme of my Wordpress (basically, "currenturlcode&wptheme=Sidebar%20disabled"). It works great, thanks to that, people will remain on the same page they are and switch the theme. However, if that is clicked on the main page, it goes to the 404 page, cause it needs to use "?" instead of "&" in case of that. So what I need help with here, is somehow making my link see if they are on the main page, and if so, adding "?wptheme=Sidebar%20disabled" there, on other cases"&wptheme=Sidebar%20disabled". Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/ Share on other sites More sharing options...
schilly Posted August 4, 2010 Share Posted August 4, 2010 so use an if statement to see if the current url is your base url then add a ?. if not then use an &. Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1095351 Share on other sites More sharing options...
Certis Posted August 4, 2010 Author Share Posted August 4, 2010 The problem is that I do not know how to do it. I don't know any php, only html and css. Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1095353 Share on other sites More sharing options...
schilly Posted August 4, 2010 Share Posted August 4, 2010 ah well that could be trouble then. can you post the code you have? Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1095356 Share on other sites More sharing options...
Certis Posted August 4, 2010 Author Share Posted August 4, 2010 Of course. This one is the code that is needed, the "brains" of the url getting, I assume. <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> And this is the link code I use (including with the php url get function. <a href="<?php echo curPageURL(); ?>&wptheme=Sidebar%20disabled">Click here</a> Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1095361 Share on other sites More sharing options...
schilly Posted August 5, 2010 Share Posted August 5, 2010 Try this <a href="<?php echo (curPageURL() = "www.domain.com") ? curPageURL() . "?wptheme=Sidebar%20disabled" : curPageURL() . "&wptheme=Sidebar%20disabled"; ?>">Click here</a> Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1095664 Share on other sites More sharing options...
Certis Posted August 8, 2010 Author Share Posted August 8, 2010 Sorry for replying so late, I was dragged to another town by my relatives, and I did not have access to internet there. Unfortunately, that solution does not work, instead, I get this error line: Fatal error: Can't use function return value in write context in /home/certis/domains/certislp.co.cc/public_html/wp-content/themes/atahualpa169/footer.php on line 24 Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1096726 Share on other sites More sharing options...
schilly Posted August 9, 2010 Share Posted August 9, 2010 ah crap. syntax error. try this. (double equals) <a href="<?php echo (curPageURL() == "www.domain.com") ? curPageURL() . "?wptheme=Sidebar%20disabled" : curPageURL() . "&wptheme=Sidebar%20disabled"; ?>">Click here</a> Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1097099 Share on other sites More sharing options...
Certis Posted August 9, 2010 Author Share Posted August 9, 2010 *Bows.* I can't thank you enough. Finally, this thing is working perfectly! I'm very grateful to you of your help! Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1097121 Share on other sites More sharing options...
schilly Posted August 9, 2010 Share Posted August 9, 2010 np =) Link to comment https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1097149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.