2011-02-16 137 views
1

这是我的问题:Zend Framework和Wordpress集成

我有require_once'../application/bootstrap.php';在zf网站的根文件夹的index.php中。我有wordpress博客进入public_html/blog。

我需要在zf网站上显示wordpress的帖子或者在zf网站内使用wordpress的所有wordpress数据。

我看了这篇文章[最后部分]但困惑什么要添加到zend/wordpress文件夹。 Zend Framework and Wordpress Integration

我的bootstrap.php文件中,我有包括“../application/default”等 路径/库和初始化和控制器的运行。

如何在我的ZF代码中调用wordpress wp_get_post?

我不需要重定向,但ZF网站

回答

1

也许最简单的方法是使用WordPress的数据库结构,而不是它的代码中使用WordPress的内容。您可以使用zend框架模型从wordpress数据库检索页面,并使用zend框架控制器操作显示它们。

如果你想在你的zend框架应用中使用wp_get_post,你必须找到wordpress函数所在的位置,然后将该文件包含到zend框架中。

2

从你只需要下面的代码插入到当前文件中的任何文件访问WordPress的功能:

<?php 
/* This make the magic: */ 
define('WP_USE_THEMES', false); 
require('path-to-the-file/wp-blog-header.php'); 

/* This retrieve the last 3 posts */ 
query_posts('showposts=3'); 
while (have_posts()) : the_post(); 
?> 
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><br /> 
<?php endwhile;?> 

干杯。

0

要从WP页面访问任何Zend Framework的功能,您可以使用此代码:

 <?php 
     // get zend framework components 
     require_once 'Zend/Loader/Autoloader.php'; 
     Zend_Loader_Autoloader::getInstance(); 

     // add your ZF code below this line 
     $your_zf_code = new Zend...; 
     echo $your_zf_code->getBaseUrl(); 

     ?> 

只要确保你是在包含路径的ZF的库文件夹。

+0

看起来OP需要的是相反的:在ZF网站上使用WP内容。 – 2013-09-16 02:47:12