Skip to content

Instantly share code, notes, and snippets.

@jbrooksuk
Created August 18, 2011 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrooksuk/86ca87b92c56b2cd7221 to your computer and use it in GitHub Desktop.
Save jbrooksuk/86ca87b92c56b2cd7221 to your computer and use it in GitHub Desktop.
ArticleContent
<?php
$AC = new articleContent();
class articleContent {
public $current_article = 0;
public $article_count = 0;
protected $in_the_loop = false;
public $articles = array();
public $article = array();
function __construct() {
global $dbDriver;
/* Article Data */
$articleQuery = $dbDriver->query("SELECT p.*, a.*, (SELECT COALESCE(COUNT(m_article_id), 0) FROM xc_meta m WHERE m.m_article_id = a._article_id) AS widgetCount FROM xc_page AS p LEFT JOIN xc_articles AS a ON p._page_id = a.a_page_id WHERE p._page_id=1 ORDER BY a.a_section_id, a.a_order_id");
$this->article_count = $articleQuery->num_rows;
while ($aRow = $dbDriver->fetch('assoc', $articleQuery)) {
$this->articles[] = $aRow;
}
}
function next_article() {
$this->current_article++;
$this->article = $this->articles[$this->current_article];
return $this->article;
}
function the_article() {
$this->in_the_loop = true;
if($this->current_article == 0) add_action('loop_start');
$this->article = $this->next_article();
}
public function have_articles() {
if($this->current_article + 1 <= $this->article_count) {
return true;
}
$this->in_the_loop = false;
return false;
}
public function __get($io) {
echo "<pre>" . print_r($this->articles[$this->current_article], true) . "</pre>";
return $this->articles[$this->current_article][$io];
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment