Hey everyone. I want to use PHP in Wordpress to only display a certain element on just one page of the website. I was thinking of using if then to do it. So for instance I want it to be something like: If page that visitor is viewing equals x then show this else show this How do I do this in PHP?
with pure php <?php $page = $_SERVER['PHP_SELF']; if($page == "/whichpage.php") { print "show this"; }else{ print "show this 2"; } ?>
Thanks Crivion, that slightly works. What should I put in the page variable if my page is not a PHP file. I'm in wordpress so my URL is like this: http://www.mysite.com/?page_id=130
The "correct" way to do this in Wordpress would probably be to make a template file with a loop that only displays what you want on that page only, and then make a new page in Wordpress with that template. But you could exchange the $page = $_SERVER['PHP_SELF']; with $page = $_GET['page_id']; (if I'm assuming right, and the variable after the ? in the link is page_id and then exchange if($page == "/whichpage.php") { with if($page == "130") { assuming that the page number is 130, of course
Thanks Popsicle, that worked. PHP is awesome, can anyone recommend any learning resources that will help me get to know this language quickly?
I am using this for reference mostly, but is an amazing collection for tutorials, not only for PHP, but for whatever you are going to use along with PHP: http://www.w3schools.com/