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 $tpl - Optional name of template file to be used (no extension) */ function __construct($tmpl_path=null, $tmpl_path = null) { // construct an object implementing the same interface as Arlima_List $list = new stdClass(); $list->options = array( 'previewtemplate' => self::DEFAULT_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 setting up wordpress environment for every post an extra time while( have_posts() ) { the_post(); global $post; $article_counter = $this->outputArticle($this->extractArticleData($post), $jQueryTmpl, $jQueryTmpl_df, null, $article_counter); if( $article_counter >= 50 ) break; } // unset global post data $GLOBALS['post'] = null; } /** * @param stdClass $post * @return array */ protected function extractArticleData(stdClass $post) { $article = array( 'post_id' => $post->ID, 'options' => array( 'hiderelated' => false ), 'title' => get_the_title($post->ID), 'title_html' => '

'.$post->post_title.'

', 'url' => get_permalink($post->ID), 'text' => '' ); $article = Arlima_ListFactory::createArticleDataArray($article); $header_callback = $this->header_callback; $article['title_html'] = $header_callback($article); $article['text'] = $post->post_content; return $article; } }