the_post() ...) */ class Arlima_WPLoop extends Arlima_ListTemplateRenderer { private $header_callback; /** * @param string $tmpl_path - Optional path to directory where templates should exists (see readme.txt about how to add your own template paths from the theme) * @param string $tmpl - Optional name of template file to be used (no extension) */ function __construct($tmpl_path=null, $tmpl = self::DEFAULT_TMPL) { // construct an object implementing the same interface as Arlima_List $list = new stdClass(); $list->options = array( 'previewtemplate' => $tmpl // todo: rename from 'previewtemplate' to 'template' ); parent::__construct($list, $tmpl_path); $this->header_callback = function($article) { return $article['html_title']; }; } /** * @param Closure $callback */ function setHeaderCallback($callback) { $this->header_callback = $callback; } /** * @return bool */ function havePosts() { return have_posts(); } function renderList() { $article_counter = 0; // Create template $jQueryTmpl_df = new jQueryTmpl_Data_Factory(); $jQueryTmpl = $this->loadTemplate(new jQueryTmpl_Factory(), new jQueryTmpl_Markup_Factory()); // Setup tmpl object creator $this->setupObjectCreator(); $this->setup_wp_post_data = false; // prevent this class from overwriting the global post object while( have_posts() ) { if($this->getOffset() > $article_counter) { $article_counter++; continue; } the_post(); global $post; $article_counter = $this->outputArticle($this->extractArticleData($post), $jQueryTmpl, $jQueryTmpl_df, $article_counter); if( $article_counter >= 50 || ($this->getLimit() > -1 && $this->getLimit() <= $article_counter) ) break; } // unset global post data $GLOBALS['post'] = null; } /** * @param stdClass $post * @return array */ protected function extractArticleData(stdClass $post) { $date = strtotime($post->post_date); $article = array( 'post_id' => $post->ID, 'options' => array( 'hiderelated' => false ), 'title' => get_the_title($post->ID), 'title_html' => '