Created
August 23, 2012 12:08
-
-
Save shawnsandy/3436056 to your computer and use it in GitHub Desktop.
Wordpress Post Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class my_post { | |
public function __construct() { | |
} | |
/** | |
* Uses WP default query to create a post loop | |
* @global type $post | |
* @param string / array $query | |
* @param string $slug / default - base | |
* @param string $name / default - general | |
* <code><?php cwp_post::loop(array('post_type' => 'cwp_articles')); ?></code> | |
*/ | |
public static function loop($query = null, $slug = null, $name = '',$base_dir='views') { | |
global $post; | |
if (isset($query)) | |
query_posts($query); | |
if (have_posts()): | |
while (have_posts()): | |
the_post(); | |
$post_type = get_post_type(); | |
$post_format = (get_post_format() ? get_post_format() : ''); | |
//***************** use format / post_type strings to change the name of slug / name | |
//sets slug based on post type | |
if($slug == 'post_type') | |
$slug = $post_type; | |
//sets name based on post_type | |
if ($name == 'post_type') | |
$name = $post_type; | |
//sets the name based on post format | |
if ($name == 'format') | |
$name = $post_format; | |
//sets the slug to page based on post_format. | |
if($post_format == 'page') | |
$slug = 'page'; | |
//default slug | |
$slug = isset($slug) ? $slug : 'content'; | |
bj_layout::get_template_part($slug, $name, $base_dir); | |
endwhile; | |
bj_content_nav('nav-below'); | |
else : | |
get_template_part('no-results'); | |
endif; | |
wp_reset_query(); | |
} | |
/** | |
* | |
* Uses WP_Query to create post loops | |
* @param string / array $query | |
* @param string $slug // default - base | |
* @param string $name // default - general | |
* <code></code> | |
*/ | |
public static function query($query = array('showposts' => 5), $slug='content', $name='',$base_dir='content') { | |
$wp = new WP_Query($query); | |
if ($wp->have_posts()): | |
while ($wp->have_posts()): | |
$wp->the_post(); | |
$post_type = get_post_type(); | |
$post_format = (get_post_format() ? get_post_format() : ''); | |
//***************** use format / post_type strings to change the name of slug / name | |
//sets slug based on post type | |
if($slug == 'post_type') | |
$slug = $post_type; | |
//sets name based on post_type | |
if ($name == 'post_type') | |
$name = $post_type; | |
//sets the name based on post format | |
if ($name == 'format') | |
$name = $post_format; | |
//sets the slug to page based on post_format. | |
if($post_format == 'page') | |
$slug = 'page'; | |
//default slug | |
$slug = isset($slug) ? $slug : 'content'; | |
bj_layout::get_template_part($slug, $name, $base_dir); | |
endwhile; | |
bj_content_nav('nav-below'); | |
else : | |
get_template_part('no-results'); | |
endif; | |
wp_reset_postdata(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment