简体   繁体   中英

Load Wordpress page content from external php

Has anyone ever used wordpress as a CMS and tried to render pages, articles and widgets on php-pages which are on the same server, but in another directory? I have to mix two CMSs as a migration strategy to wordpress.

Lets say wordpress is installed in folder ./wp and there is a page with permalink /wp/testpage. I create a file test.php in folder ./tests/ What I alreay tried is:

<?php 
  global $page; 
  $page = 616; //looked up post id

 require_once '../wp/index.php';

?>

But that just shows me a 404 wordpress page - footer and header are loaded correctly, but not the content.

you need to require the wp-load.php file from the blog you need. Then you can get the content from the blog using the wordpress functions.

<?php
require_once("../wp/wp-load.php");
$my_postid = 616;
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);

echo $content;

not tested but I have it similar to this somewhere in my php files.
edit: just tested. Works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM