开发者

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.

    <?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_开发者_Python百科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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜