...

View Full Version : Include some outside code in Wordpress



TripBR
03-31-2010, 02:30 PM
Hello!

I would like to know how can I include a piece of external code in the wordprpress.

I tried to add my code in the footer.php (wp-content/themes) but whit no suces..

This is the code that i need to add:


<?php
$site_id = "48";
include('banner.php');
?>

But when I try to run my blog I got several MySQL errors.

banner.php have it's own class that call an external MySQL, and I can't iframe this because I need to capture referer...

Some one have some idea?

xconspirisist
03-31-2010, 03:12 PM
Could you be more descriptive as to your problem, or error message?

The code that you have there is correct to include a local php file.

TripBR
03-31-2010, 04:08 PM
Could you be more descriptive as to your problem, or error message?

The code that you have there is correct to include a local php file.

I think the problem is that my script banner.php calls other MySQL connection, and I don't know why I cant call other MySQL connection...

The error is very simple: "Error: Can't connect to localhost"

But when I iframe test.php that have this code included, the code runs well...

DJCMBear
03-31-2010, 05:59 PM
If your connecting to a different database you need to close the connection thats open at the moment before you can do that.

TripBR
03-31-2010, 06:08 PM
If your connecting to a different database you need to close the connection thats open at the moment before you can do that.

Yeah, I'm pretty sure about this. But how can I close the main Wordpress MySQL connection if it will need it to execure the other part of the code?

DJCMBear
03-31-2010, 06:12 PM
find out where they open then db, like sometimes people use $con = mysql_query(""); all you need to do then is put mysql_close($con); just before your code but you have to reopen the other db after you have finished using yours or WP wont work.

abduraooft
03-31-2010, 06:21 PM
If your connecting to a different database you need to close the connection thats open at the moment before you can do that.
Are you sure? I don't think so.

TripBR
03-31-2010, 06:40 PM
find out where they open then db, like sometimes people use $con = mysql_query(""); all you need to do then is put mysql_close($con); just before your code but you have to reopen the other db after you have finished using yours or WP wont work.

Are u sure that your idea will work?

Are u talking about this?

$wp->dbcloseclass();
include('mycode.php');
$wp->dbopenclass();

I'm trying the Wordpress suport forum, but no one replyed to me yet...

DJCMBear
03-31-2010, 06:49 PM
well it looks ok but what you was trying to do was access a table in a different db but because you didnt close the other one php was looking inside the WP db not yours.

TripBR
03-31-2010, 07:00 PM
well it looks ok but what you was trying to do was access a table in a different db but because you didnt close the other one php was looking inside the WP db not yours.

Yeah, I think so..

As i said, I'm tryng the wordpress suport forum to know what's the class to close and reopen the connection, after that is aswered I'll try out your idea. :thumbsup:

DJCMBear
03-31-2010, 07:02 PM
Yeah, I think so..

As i said, I'm tryng the wordpress suport forum to know what's the class to close and reopen the connection, after that is aswered I'll try out your idea. :thumbsup:

arite well the WP forum is the best place to ask because they are the people who made it and would know it back to front lol.

TripBR
03-31-2010, 07:08 PM
arite well the WP forum is the best place to ask because they are the people who made it and would know it back to front lol.

bit off topic: i know that there is the best place to ask about this, but I'm on it from 2 days now, and no aswers...

DJCMBear
03-31-2010, 07:40 PM
well they are a populare system so they do have many people to contact. But 2 days is abit to long really.

abduraooft
04-01-2010, 09:20 AM
The error is very simple: "Error: Can't connect to localhost"
The error might be very simple, but error checks that you've added in your code looks very poor. Could you post the code in your banner.php here?

katierosy
04-01-2010, 03:18 PM
http://codex.wordpress.org/Pages#Page_Templates

You may create a custom page in wordpress. Use include page plugin, if you do not want to create a word press plugin for your banner application.

TripBR
04-01-2010, 05:54 PM
http://codex.wordpress.org/Pages#Page_Templates

You may create a custom page in wordpress. Use include page plugin, if you do not want to create a word press plugin for your banner application.

Yeah I know this too, but I *NEED* that my included script stay on the footer of some template. My problem is that my script need a SQL connection, but of course it will give me some error 'cause WordPress have an active connection when my script is included...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum