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, $tpl = self::DEFAULT_TMPL) { // construct an object implementing the same interface as Arlima list $list = new stdClass(); $list->options = array( 'previewtemplate' => $tpl // todo: rename from 'previewtemplate' to 'template' ); parent::__construct($list, $tmpl_path); $this->header_callback = function($article) { return $article['html_title']; }; } 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()); $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->posToArlimaArticle($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 posToArlimaArticle(stdClass $post) { $article = array( 'post_id' => $post->ID, 'options' => array( 'hiderelated' => false ), 'title' => $post->post_title, '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'] = apply_filters('the_content', get_the_content()); return $article; } }