Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Does anyone know how to put PHP on Wordpress pages?
Old 01-24-2009, 06:04 PM Does anyone know how to put PHP on Wordpress pages?
Experienced Talker

Posts: 38
Name: carl
Trades: 0
Anyone? Im running WPMU and want to add PHP script to a page for searching.
Exbrief is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-24-2009, 06:12 PM Re: Does anyone know how to put PHP on Wordpress pages?
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
There is a plugin called exec-php that will allow you to execute php code in posts:

http://bluesome.net/post/2005/08/18/50/

If you are also trying to display php code for examples or tutorials, this plugin will likely attempt to execute that code as well. I've made a modified version, fixing this problem, that I'm using (without any problems) on my blog, but hasn't been widely tested. You can download that here if you wish to give it a shot:

http://tinsology.net/files/exec-php4.9modified.zip
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-24-2009 at 06:13 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-24-2009, 07:50 PM Re: Does anyone know how to put PHP on Wordpress pages?
Experienced Talker

Posts: 38
Name: carl
Trades: 0
Quote:
Originally Posted by NullPointer View Post
There is a plugin called exec-php that will allow you to execute php code in posts:

http://bluesome.net/post/2005/08/18/50/

If you are also trying to display php code for examples or tutorials, this plugin will likely attempt to execute that code as well. I've made a modified version, fixing this problem, that I'm using (without any problems) on my blog, but hasn't been widely tested. You can download that here if you wish to give it a shot:

http://tinsology.net/files/exec-php4.9modified.zip
Wow, I tried that, followed all the instructions and even added the optional plugins, etc. All I get is a blank page when looking at the page. Anyone know of an easier way? You runnimg Wordpress or Wordpress MU?

Last edited by Exbrief; 01-24-2009 at 07:52 PM..
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 01-24-2009, 08:48 PM Re: Does anyone know how to put PHP on Wordpress pages?
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
I'm not using MU, but that shouldn't matter. All the plugin does is take a page's content from the database and passes it through eval, the output of eval is what is printed. Make sure you code works independently from WP.

WP also has a tendency to convert your php tags so watch out for things like that as well.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-24-2009 at 08:49 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-24-2009, 08:49 PM Re: Does anyone know how to put PHP on Wordpress pages?
Experienced Talker

Posts: 38
Name: carl
Trades: 0
I am copying my code from a working copy I have running. No errors with the code, it works perfectly as a stand alone.

I tried to create a Wordpress page template per the instructions in the Wordpress Codex.....


Here is the issue. My script works perfectly as its own page, but when I put it into the template and hit search...the index.php comes up instead of the search results. Any ideas?

Code:
<?php
/*
Template Name: Browse ExBriefs
*/
?>

<?php get_header(); ?>

    <div id="content" class="narrowcolumn">

<h2>Search</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="first">First Name</option>
<Option VALUE="last">Last Name</option>
<Option VALUE="city">City</option>
<Option VALUE="state">State</option>
<Option VALUE="country">Country</option>
<Option VALUE="gender">Gender</option>

</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>

<?PHP
//This is only displayed if they have submitted the form
if ($_POST[searching] =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($_POST[find] == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

// We preform a bit of filtering
$find = strtoupper($_POST[find]);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified


$data=mysql_query("select * from contacts where ".$_POST[field]." like '%".addslashes($find)."%'");

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['first'];
echo " ";
echo $result['last'];
echo "<br>";
echo $result['city'];
echo "<br>";
echo $result['state'];
echo "<br>";
echo $result['country'];
echo "<br>";
echo $result['gender'];
echo "<br>";
echo "<br>";
}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, there is no Ex-Brief for <b>\"$find\"</b> yet
Please try again.<br><br>";
}

}

?>


    

    </div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 01-24-2009, 10:36 PM Re: Does anyone know how to put PHP on Wordpress pages?
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
The problem might be with PHP_SELF. Try printing PHP_SELF to see what the value is. Also if register globals is not on PHP_SELF will not be set (use $_SERVER['PHP_SELF'])
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-24-2009 at 10:38 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-24-2009, 11:11 PM Re: Does anyone know how to put PHP on Wordpress pages?
Experienced Talker

Posts: 38
Name: carl
Trades: 0
that did not work. that was a good idea though. Maybe I should break it up into 2 files the HTML form in the first and have it call the PHP script separately. I will try that unless you have a better idea.
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 01-25-2009, 12:00 AM Re: Does anyone know how to put PHP on Wordpress pages?
Experienced Talker

Posts: 38
Name: carl
Trades: 0
Whooo Hooo Splitting up the html and php into 2 seperate wordpress templates did the trick. thanks for all your help!
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 01-27-2009, 08:45 AM Re: Does anyone know how to put PHP on Wordpress pages?
Novice Talker

Posts: 15
Name: Jamal
Trades: 0
Quote:
Originally Posted by Exbrief View Post
Wow, I tried that, followed all the instructions and even added the optional plugins, etc. All I get is a blank page when looking at the page. Anyone know of an easier way? You runnimg Wordpress or Wordpress MU?

you need to see in the permissions of the files as said in the manual.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
scriptbazaar is offline
Reply With Quote
View Public Profile
 
Old 01-27-2009, 03:20 PM Re: Does anyone know how to put PHP on Wordpress pages?
Experienced Talker

Posts: 38
Name: carl
Trades: 0
i just created templates and that worked. thanks
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 01-29-2009, 06:58 AM Re: Does anyone know how to put PHP on Wordpress pages?
Average Talker

Posts: 22
Name: Andrew McGrath
Trades: 0
Quote:
Originally Posted by Exbrief View Post
i just created templates and that worked. thanks
Yeah, I did the same thing with my site.

I think this is probably the most secure, fastest and most straight-forward method.
__________________

Please login or register to view this content. Registration is FREE
- Search engine optimisation articles.
Please login or register to view this content. Registration is FREE
- Video search.
Please login or register to view this content. Registration is FREE
- Watch, download and keep YouTube videos.
Please login or register to view this content. Registration is FREE
- Advice on relationships, etiquette and everyday life.
andmcg1 is offline
Reply With Quote
View Public Profile
 
Old 01-31-2009, 01:09 AM Re: Does anyone know how to put PHP on Wordpress pages?
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
The best one I know about is Exec PHP

http://wordpress.org/extend/plugins/exec-php/

If you have any more issues you should check it out.
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to Does anyone know how to put PHP on Wordpress pages?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33754 seconds with 12 queries