Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-13-2009, 08:13 PM   PM User | #1
EasyCoding
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
EasyCoding is an unknown quantity at this point
Unhappy Wordpress: Use a sidebar (widget) from different blog?

Is it possible to call in a widget from a different blog installed on the same URL?

This is what I put in for the code of the widget where I want it to be called into:

PHP Code:
<?php require ('http://www.imperial-mag.com/blog/wp-content/themes/Imperial_NEW/widgets/recent'); ?>
It comes up with an error message as you can see here: http://www.imperial-mag.com/wordpress/

Any help is appreciated.

thanks in advance.
EasyCoding is offline   Reply With Quote
Old 08-13-2009, 08:25 PM   PM User | #2
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
Using relative urls, should be something like this

PHP Code:
<?php require('/home/content/i/m/p/imperialmag/html/wordpress/wp-content/themes/Imperial_NEW/widgets/recent.php'); ?>
mr e is offline   Reply With Quote
Old 08-13-2009, 08:30 PM   PM User | #3
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
I think the URL you are calling does not exist. I have checked and I am not able to access it.
ckeyrouz is offline   Reply With Quote
Old 08-13-2009, 08:32 PM   PM User | #4
EasyCoding
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
EasyCoding is an unknown quantity at this point
Hey that worked!

One problem though. It's not pulling in the posts from the "blog" section.

The posts are here: http://www.imperial-mag.com/blog/

You can see here: http://www.imperial-mag.com/wordpress that the posts from the blog page are not being pulled in.
EasyCoding is offline   Reply With Quote
Old 08-13-2009, 08:41 PM   PM User | #5
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
If you have two different blogs running, you'll need to make sure the code you're including knows which database to access, otherwise it will simply access the database of the blog doing the including, instead of the blog it started in.

Make sense?

There are a few ways to do this, the way I would probably do it is to change the widget to output some html and file_get_contents that.

So for example
PHP Code:
// blog's news-widget.php
//   pull some info from the database
//   output html directly

//  main site
//    file_get_contents('http://www.yoursite.com/wp-content/themes/whatever/widgets/news-widget.php'); 
Not very hard, you just need to approach it slightly differently than you are now
mr e is offline   Reply With Quote
Old 08-13-2009, 08:43 PM   PM User | #6
EasyCoding
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
EasyCoding is an unknown quantity at this point
Quote:
Originally Posted by mr e View Post
If you have two different blogs running, you'll need to make sure the code you're including knows which database to access, otherwise it will simply access the database of the blog doing the including, instead of the blog it started in.

Make sense?

There are a few ways to do this, the way I would probably do it is to change the widget to output some html and file_get_contents that.

So for example
PHP Code:
// blog's news-widget.php
//   pull some info from the database
//   output html directly

//  main site
//    file_get_contents('http://www.yoursite.com/wp-content/themes/whatever/widgets/news-widget.php'); 
Not very hard, you just need to approach it slightly differently than you are now
I am sorry - totally lost on this.

I am at a beginner level on PHP.

Can you explain further? Thanks.
EasyCoding is offline   Reply With Quote
Old 08-13-2009, 09:46 PM   PM User | #7
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
This might be a better direction for you to go if you're new to PHP

http://wphacks.com/how-to-adding-an-...ordpress-blog/
mr e is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 04:00 AM.


Advertisement
Log in to turn off these ads.