How to exclude an added(to page.php) code from pages?(Wordpr

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cini
Forum Newbie
Posts: 3
Joined: Wed Jun 16, 2010 2:33 am

How to exclude an added(to page.php) code from pages?(Wordpr

Post by cini »

In my blog,i have to add a code to the page.php (a must for me)

I added the code and works fine in a specific page which i created but the problem is that,when i added the code all the other pages like contact,privacy policy shows it.I just want to show it in that specific page i created

An example:I created a page let's say X.I added below code to page.php
<?php if
(function_exists('fvCommunityNewsForm'))
fvCommunityNewsForm(); ?>

All the pages(contact,privacy policy) effected from this code.I don't want this code to be shown in those pages but only X page

Is there a way to exclude that code from other pages not to show it?
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: How to exclude an added(to page.php) code from pages?(Wo

Post by aravona »

There is a way and off the top of my head I can't completely remember how. We use a similar thing with headers, wanting different flash objects to show up on different page headers. You can do it within a template in WP, however I've not done it myself and would have to ask. Alternatively, you could try using a case. I also did one using a set of IF statements based on page url using a snippet of code whichs grabs the url and then displays a picture based on whether the variable I set up was equilivant to that of the current page.

http://codex.wordpress.org/Pages#Creati ... _Templates < That may be of some use, but being a wordpress dev myself I know just how long their info pages are.
cini
Forum Newbie
Posts: 3
Joined: Wed Jun 16, 2010 2:33 am

Re: How to exclude an added(to page.php) code from pages?(Wo

Post by cini »

Someone told me to try something like this

if(get_the_ID()==2){ .................

2 is the ID of page X
but didn't work
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: How to exclude an added(to page.php) code from pages?(Wo

Post by aravona »

Like I said before you may simply have to set up a template for that page, so that it uses the code, and other pages use a different template.
cini
Forum Newbie
Posts: 3
Joined: Wed Jun 16, 2010 2:33 am

Re: How to exclude an added(to page.php) code from pages?(Wo

Post by cini »

Ok got the solution

<?php
if(get_the_ID()==2){
if (function_exists('fvCommunityNewsForm'))
fvCommunityNewsForm();
}
?>


2 is the ID of the page

When i write the ID of the page it only shows on that specific page
Post Reply