Сори, туплю..
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Post extends Model
{
protected $_tablePosts = 'wp_posts';
protected $_tableUsers = 'wp_users';
protected $_tableTerms1 = 'wp_term_relationships';
protected $_tableTerms2 = 'wp_terms';
protected $_tableTerms3 = 'wp_term_taxonomy';
public function get_all()
{
$query = DB::select('wp_users.*', 'wp_posts.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->where('wp_posts.post_status', '=', 'publish')
->order_by('post_date', 'desc')
->limit(10);
$result = $query->execute()->as_array();
return $result;
}
public function get_n()
{
$query = DB::select('wp_users.*', 'wp_posts.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_posts.post_author', '=', 'wp_users.id')
->where('wp_posts.post_status', '=', 'publish')
->order_by('post_date', 'desc')
->limit(2);
$result = $query->execute()->as_array();
return $result;
}
public function get_pages()
{
$query = DB::select()
->from($this->_tablePosts)
->where('wp_posts.post_type', '=', 'page')
->order_by('menu_order');
$result = $query->execute()->as_array();
return $result;
}
public function get_page($id = '')
{
$query = DB::select('wp_users.*', 'wp_posts.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->where('wp_posts.post_type', '=', 'page')
->where('wp_posts.id', '=', $id)
->order_by('menu_order')//;
->limit(1);
$result = $query->execute()->as_array();
return $result;
}
public function get_list()
{
$query = DB::select('wp_users.*', 'wp_posts.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->where('wp_posts.post_status', '=', 'publish')
->order_by('post_date', 'desc')
->limit(10);
$result = $query->execute()->as_array();
return $result;
}
public function get_article($id = '')
{
$query = DB::select('wp_posts.*', 'wp_users.*', 'wp_term_relationships.*', 'wp_terms.*', 'wp_term_taxonomy.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->join($this->_tableTerms1)->on('wp_posts.ID', '=', 'wp_term_relationships.object_id')
->join($this->_tableTerms2)->on('wp_term_relationships.term_taxonomy_id', '=', 'wp_terms.term_id')
->join($this->_tableTerms3)->on('wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')
->where('wp_posts.post_status', '=', 'publish')
->where('wp_posts.ID', '=', $id)
->order_by('post_date', 'desc')
->group_by('posts_id');
$result = $query->execute()->as_array();
return $result;
}
public function get_cat_n()
{
$query = DB::select('wp_posts.*', 'wp_users.*', 'wp_term_relationships.*', 'wp_terms.*', 'wp_term_taxonomy.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->join($this->_tableTerms1)->on('wp_posts.ID', '=', 'wp_term_relationships.object_id')
->join($this->_tableTerms2)->on('wp_term_relationships.term_taxonomy_id', '=', 'wp_terms.term_id')
->join($this->_tableTerms3)->on('wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')
->where('wp_posts.post_status', '=', 'publish')
->where('taxonomy', '=', 'category')
->order_by('post_date', 'desc')
->group_by('wp_terms.term_id');
$result = $query->execute()->as_array();
return $result;
}
public function get_cat_n_n()
{
$query = DB::select('wp_posts.*', 'wp_users.*', 'wp_term_relationships.*', 'wp_terms.*', 'wp_term_taxonomy.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->join($this->_tableTerms1)->on('wp_posts.ID', '=', 'wp_term_relationships.object_id')
->join($this->_tableTerms2)->on('wp_term_relationships.term_taxonomy_id', '=', 'wp_terms.term_id')
->join($this->_tableTerms3)->on('wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')
->where('wp_posts.post_status', '=', 'publish')
->where('taxonomy', '=', 'category')
->order_by('post_date', 'desc')
->limit(5);
$result = $query->execute()->as_array();
return $result;
}
public function get_category($id = '')
{
$query = DB::select('wp_posts.*', 'wp_users.*', 'wp_term_relationships.*', 'wp_terms.*', 'wp_term_taxonomy.*', array('wp_users.id', 'users_id'), array('wp_posts.id', 'posts_id'))
->from($this->_tablePosts)
->join($this->_tableUsers)->on('wp_users.id', '=', 'wp_posts.post_author')
->join($this->_tableTerms1)->on('wp_posts.ID', '=', 'wp_term_relationships.object_id')
->join($this->_tableTerms2)->on('wp_term_relationships.term_taxonomy_id', '=', 'wp_terms.term_id')
->join($this->_tableTerms3)->on('wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')
->where('wp_posts.post_status', '=', 'publish')
->where('wp_terms.term_id', '=', $id)
->order_by('post_date', 'desc')
->group_by('posts_id')
->limit(10);
$result = $query->execute()->as_array();
return $result;
}
}
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Main extends Controller_Template {
public $template = 'basic';
public function action_index()
{
$posts = array();
$articles = array();
$cats = array();
$navs = array();
$content = View::factory('themes/home')
->bind('posts', $posts)
->bind('articles', $articles)
->bind('cats', $cats)
->bind('navs', $navs);
$posts = Model::factory('Post')->get_cat_n_n();
$articles = Model::factory('Post')->get_list();
$cats = Model::factory('Post')->get_cat_n();
$navs = Model::factory('Post')->get_pages();
$this->template->content = $content;
}
}