Integrate Wordpress Post with Cakephp3

戏子无情 提交于 2019-12-08 16:15:57

问题


I am working on cakephp 3.x and want to display blogs section on my site. I want to use WordPress feature in my site.

I have installed WordPress 4 on my local server, then I have imported tables of WordPress into cake's database and put the WordPress folder into webroot folder of Cakephp.

In app controller's initialize() function I have put this code as follows:

    global $wpdb;
    define('WP_USE_THEMES', false);
    require($_SERVER['DOCUMENT_ROOT']."/webroot/blog/wp-config.php");

So that I can embed WordPress into cakephp (seems this is not helpful).

I have tried this tutorial but not success on this Tutorial Link.

I know in this tutorial Wordpress folder is placed out of webroot folder and I have tried that too.

When I run the site using http:example.com/blog

It is asking for blog controller and I understand this is because of as blog controller is not present in src/controller folder.

I have tried .htaccess code as per suggested in tutorial but no success on that. Can anyone help me out from this problem? Please let me know the required steps for integration.


回答1:


You can use the "API"

<?php
require('/the/path/to/your/wp-blog-header.php');

$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

Source: http://codex.wordpress.org/Integrating_WordPress_with_Your_Website

Or try WP API ;)



来源:https://stackoverflow.com/questions/35555960/integrate-wordpress-post-with-cakephp3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!