Created
June 22, 2012 21:16
-
-
Save ekka21/2975251 to your computer and use it in GitHub Desktop.
Wordpress: Post lists base on category
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
/* Posts List base on category*/ | |
function imediapixel_postslist($category, $num, $orderby="date",$style="2col") { | |
global $post; | |
$category_id = get_cat_ID($category); | |
$cat_num = ($num) ? $num : 4; | |
$counter = 0; | |
$out = ""; | |
query_posts('cat='.$category_id.'&showposts='.$cat_num.'&orderby='.$orderby); | |
while (have_posts()) : the_post(); | |
$counter++; | |
if ($style == "2col") { | |
if ($counter %2 ==0) { | |
$out .= '<div class="mainbox box-last">'; | |
} else { | |
$out .= '<div class="mainbox">'; | |
} | |
$out .= '<h4><a href="'.get_permalink().'">'.get_the_title().'</a></h4>'; | |
$out .= '<div class="boximg">'; | |
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { | |
$out .= '<img src="'.get_template_directory_uri().'/timthumb.php?src='.thumb_url().'&h=84&w=84&zc=1" alt="" class="boximg-pad" />'."\n"; | |
} | |
$out .= '</div>'; | |
$out .= '<p>'.excerpt(25).'</p>'; | |
$out .= '<a href="'.get_permalink().'" class="button"><span>'.__('VIEW MORE DETAIL ','ecobiz').'<img src="'.get_template_directory_uri().'/images/arrow_grey.png" alt="" class="readmore"/></span></a>'; | |
$out .= '</div>'; | |
if ($counter %2 ==0) { | |
$out .= '<div class="spacer"></div>'; | |
} | |
} else if ($style == "3col"){ | |
if ($counter %3 ==0) { | |
$out .= '<div class="mainbox2 box-last">'; | |
} else { | |
$out .= '<div class="mainbox2">'; | |
} | |
$out .= '<h4><a href="'.get_permalink().'">'.get_the_title().'</a></h4>'; | |
$out .= '<div class="boximg2">'; | |
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { | |
$out .= '<img src="'.get_template_directory_uri().'/timthumb.php?src='.thumb_url().'&h=78&w=182&zc=1" alt="" class="boximg-pad" />'."\n"; | |
} | |
$out .= '</div>'; | |
$out .= '<p>'.excerpt(8).'</p>'; | |
$out .= '<a href="'.get_permalink().'" class="button"><span>'.__('VIEW MORE DETAIL ','ecobiz').'<img src="'.get_template_directory_uri().'/images/arrow_grey.png" alt="" class="readmore"/></span></a>'; | |
$out .= '</div>'; | |
if ($counter %3 ==0) { | |
$out .= '<div class="spacer"></div>'; | |
} | |
} | |
endwhile; | |
wp_reset_query(); | |
return $out; | |
} | |
/* ====================================== | |
Post list base on category | |
[postlist $category, $num, $orderby="date",$style="2col"] | |
======================================*/ | |
function imediapixel_postlist_shortcode($atts,$content=null) { | |
global $post; | |
extract(shortcode_atts(array( | |
"category" => '', | |
"num" => '', | |
"orderby" => '', | |
"style" => '' | |
),$atts)); | |
if ($style == "") $style = "2col"; | |
if ($orderby == "") $orderby = "date"; | |
return imediapixel_postslist($category, $num, $orderby,$style); | |
} | |
add_shortcode('postlist','imediapixel_postlist_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment