Skip to content

Instantly share code, notes, and snippets.

@epicallan
Last active August 29, 2015 14:15
Show Gist options
  • Save epicallan/c3c3025248a9c33581b4 to your computer and use it in GitHub Desktop.
Save epicallan/c3c3025248a9c33581b4 to your computer and use it in GitHub Desktop.
Creating modular wordpress page templates with classes
<?php
/**
* themes class
* included on page templates by use of
* a template redirect hook
*/
class ThemeClass
{
protected $data;
public function __construct($init)
{
$this->data = $init;
$this->type = $init["type"];
$this->prefix = $init["prefix"];
$this->taxonomy=$init["taxonomy"];
$this->table_id=$init["table_id"];
}
public function getData()
{
$type = $this->type;
$prefix = $this->prefix;
$taxonomy=$this->taxonomy;
$table_id=$this->table_id;
$args = array('post_type' => $type, 'post_status' => 'publish', 'posts_per_page' => -1, 'ignore_sticky_posts' => 1);
// The Query
$prefix = $prefix;
$query1 = new WP_Query($args);
// The Loop
while ($query1->have_posts()) {
//**code**/
//loop logic
}
wp_reset_postdata();
}
public function themeLogic(){
/**code**/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment