wordpress - 500 internal server error when try to include wp-load.php in codeigniter site -


i have setup wordpress blog @ www.example.com/blog , codeigniter site @ www.example.com. trying display recent post blog codeigniter site. it, included wp-load.php file using

require($_server['document_root'] . '/blog/wp-load.php');     // require_once('../app/blog/wp-load.php');                          $args = array(                               // 'cat' => 3, // source posts specific category                               'posts_per_page' => 4 // specify how many posts you'd display                               );                               $latest_posts = new wp_query( $args );                                 if ( $latest_posts->have_posts() ) {                                 while ( $latest_posts->have_posts() ) {                                 $latest_posts->the_post(); ?>                              <marquee align="top" behavior="scroll" onmouseover="this.stop();" onmouseout="this.start();" direction="up" scrolldelay="200" ><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">                              <li>                                <?php if ( has_post_thumbnail() ) { ?>                                 <span class="post_thumbnail"><?php the_post_thumbnail(); ?></span>                               <?php } ?>                               <span class="post_title"><?php the_title(); ?></span>                             </a>                             <!--span class="post_time">posted on <?php the_time('l js f, y') ?></span-->                             <?php //the_excerpt(); ?>                           </li>                            </marquee >                         <? }                              } else {                             echo '<p>there no posts available</p>';                           }                           wp_reset_postdata();                          ?> 

but throws internal server error. have change file permission? please help. site hosted godaddy.

error detail :

internal server error

the server encountered internal error or misconfiguration , unable complete request.

please contact server administrator inform of time error occurred , of might have done may have caused error.

more information error may available in server error log.

never include wordpress file in main website can lead many errors. instead, use codeigniter's second database connection connect wordpress database. searching get wordpress posts database codeigniter have found gist , this article. following code taken article. note code codeigniter 2 , code not tested. have dealt many databases in codeigniter before, ask if find trouble.

a. add different settings data in application/config/database.php file along side main website database settings:

$db['wordpress']['hostname'] = "wordpress_db_host"; // database host $db['wordpress']['username'] = "wordpress_db_username"; // db user name $db['wordpress']['password'] = "wordpress_db_password"; // db user password $db['wordpress']['database'] = "wordpress_db"; // database name 

b. build wordpress model in application/models/wordpress_model.php:

<?php if (!defined('basepath')) die ('no direct script access allowed!');  class wordpress_model extends ci_model {     function getposts()     {         $this->load->database('wordpress', true); // load database          // wordpress posts, customize         $this->wordpress->select("post_id, post_title, post_content");         $this->wordpress->from('post_tbl');         $this->wordpress->limit(5);         $query = $this->wordpress->get();         $data['posts'] = $query->result();          $this->load->view('wordpress_posts_view', $data); // load view file , passing $data array view file     } } 

c. create view file in application/views/wordpress_posts_view.php:

<h4>display records database using codeigniter</h4> <table>     <tr>         <td><strong>post id</strong></td>         <td><strong>post title</strong></td>     </tr>     <?php foreach($posts $post){?>         <tr>             <td><?php echo $post->post_id;?></td>             <td><?php echo $post->post_title;?></td>         </tr>         <?php }?>   </table> 

d. now, can call in codeigniter controller:

<?php if (!defined('basepath')) die ('no direct script access allowed!');  class homepage extends ci_controller {     public function index()     {         $this->load->model('wordpress_model');          $data['wordpress_html_posts'] = $this->wordpress_model->getposts();         print_r($data['wordpress_html_posts']);     } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -