Using the wordpress loop in a random file

For my frontpage I am using FrontPageSlideshow which generates a html/css/javascript element that displays articles and what not. Currently, it pull static entries from a file. I was able to make it dynamic for a Drupal site I worked on but now I’m stuck on a WordPress one.

In the file I try to include a php file located within my WordPress theme.

Read More
    <?php

$show = new WP_Query();

$show = query_posts(array(
     'category_name'      => 'News', 
     'posts_per_page'     => 4, 
     'orderby'       => 'date', 
     'order'         => 'DESC',
    ));

if (have_posts()) :
 while (have_posts()) : the_post() :
  $recentStories['article'.$articleNumber] = array(
   id      => $post->ID,
   title   => wp_title(),
   summary_name  => $post->post_name,
   dateMade=> the_date(),
   image   => get_post_meta($post->ID, 'fp_image', true),
   summary => get_excerpt()
   );
  $articleNumber++;
 endwhile;
endif;

?>

However the problem is that it doesn’t seem to be able to return any of my WordPress posts. This file is included in another file along the lines of

$articleNumber = 1;
$recentStories = array();

include("wp-content/themes/Website/frontpage-post.php");

$slides = array();

// --- Start slide list ---
for ( $counter = 1; $counter <= 4; $counter++) {
 // slide elements
 array_push($slides, array(
  'slidelink'  => 'http://IPHERE/website/?p=' . $recentStories['article'.$counter]['id'],
  'title'      => $recentStories['article'.$counter]['title'],
  'category'   => 'News',
  'tagline'    => $recentStories['article'.$counter]['summary'],
  'text'       => $recentStories['article'.$counter]['summary_name'],
  'slideimage' => $recentStories['article'.$counter]['image'],
  ) 
 );
};

However, my loop keeps returning an empty array. I was wondering if it was possible to use the WordPress loop outside of say the index.php page.

Related posts

Leave a Reply

1 comment

  1. For everything wordpress that is accessed outside wordpress system, you HAVE to include wp-load.php

    include("wp-load.php");
    include("wp-content/themes/Website/frontpage-post.php");