Jump to content

[SOLVED] PHP Include not working server side


SJF

Recommended Posts

Interestingly enough, when I test this on another server with another site I did, and used the original include (which works fine on that server) it works fine when including two pages.

 

This is what works, to show both pages, on the previous site.

<?php include("http://www.theirsite.com/content/?p=95"); ?>
<?php include("http://www.theirsite.com/content/?p=228"); ?>

 

But when I do the same exactly thing with the code you gave me... via:

   <?php
   $_GET['p'] = 95;
   $WPdir = dirname(__FILE__)."/content";
   chdir($WPdir);
   include($WPdir."/index.php");
   ?>

   <?php
   $_GET['p'] = 228;
   $WPdir = dirname(__FILE__)."/content";
   chdir($WPdir);
   include($WPdir."/index.php");
   ?>

...it doesn't show the second included post.

 

So somehow the code you gave me and the one that is working isn't matching to call the same things from the server.

 

Quick question, since I'm a newb at PHP here, when the URL says "?p=228" at the end of it, the only way of calling that variable p is via a $_GET?  I'm just trying to narrow it down.  Hope this helps some.

 

(I can not link since I don't have their permission to)

Link to comment
Share on other sites

Yes P=228 is $_GET['p'] = 228

 

WP has code that stops it loading twice,, the old code connects to itself by going out then back in, and opens 2 connections, where as a normal include doesn't go out,

*thinking of options*

Let me install WP on my local PC and I'll have a look

Link to comment
Share on other sites

okay new idea, try this

 

<?php
$WPdir = dirname(__FILE__)."/content";
chdir($WPdir);
require_once("adapter.php"); 

echo getPost(95);
echo getPost(228);
?>

 

 

adapter.php must be in the WP folder

<?php
require('wp-config.php');
mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME);

function getPost($id)
{
$vars = mysql_query(sprintf("SELECT post_content FROM wp_posts WHERE post_status = 'publish' AND  ID = %d", $id) );
$row = mysql_fetch_assoc($vars);
return $row['post_content'];
}
?>

Link to comment
Share on other sites

Cool again :)

this was my third option, create an adapter, please note I am very new to WP (as in about an hour new) so it may not cover everything but from an overview I think it should cover the main part (getting the post) things like comments etc are not included but can be added.

 

i hope it works for you :)

 

Link to comment
Share on other sites

Yea it's all good.  I won't need comments, etc.  It's just for content managing.  Thanks again!  You might be interested in this site - www.chipin.com maybe put it on your signature?  People can give you money for thanks!  Haha, instead of a "buy a drink" button!  I'll throw a couple dollars your way!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.