Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created June 22, 2012 21:11
Show Gist options
  • Save ekka21/2975228 to your computer and use it in GitHub Desktop.
Save ekka21/2975228 to your computer and use it in GitHub Desktop.
Wordpress: Page with child pages List
/* Page with child pages List */
function imediapixel_pagelist($page_name, $num, $orderby="menu_order",$style="2col") {
global $post;
$page_id = get_page_by_title($page_name);
$services_num = ($num) ? $num : 4;
$counter = 0;
$out = "";
if ($style == "4col") $out .= '<div class="clear"></div><ul class="portfolio-4col">';
query_posts('post_type=page&post_parent='.$page_id->ID.'&showposts='.$services_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().'&amp;h=84&amp;w=84&amp;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().'&amp;h=78&amp;w=182&amp;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>';
}
} else if ($style == "4col"){
$out .= '<li';
if ($counter %4 == 0) $out .= ' class="last"';
$out .= '>';
$out .= '<div class="portfolio-blockimg3">';
$out .= '<div class="portfolio-imgbox3">';
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
$out .= '<img src="'.get_template_directory_uri().'/timthumb.php?src='.thumb_url().'&amp;h=86&amp;w=196&amp;zc=1" alt="" class="boximg-pad" />'."\n";
}
$out .= '</div>';
$out .= '<h4><a href="'.get_permalink().'">'.get_the_title().'</a></h4>';
$out .= '<p>'.excerpt(15).'</p>';
$out .= '<a href="'.get_permalink().'" class="button"><span>'.__('VIEW DETAIL ','ecobiz').'<img src="'.get_template_directory_uri().'/images/arrow_grey.png" alt="" class="readmore"/></span></a>';
$out .= '</div>';
$out .= '</li>';
}
endwhile;
if ($style == "4col") $out .= '</ul>';
wp_reset_query();
return $out;
}
/* ======================================
Child pages list base on parent page
[pagelist parent_page="about" style="2col" num="5" ]
======================================*/
function imediapixel_pagelist_shortcode($atts,$content=null) {
global $post;
extract(shortcode_atts(array(
"parent_page" => '',
"num" => '',
"orderby" => '',
"style" => ''
),$atts));
if ($style == "") $style = "3col";
if ($orderby == "") $orderby = "date";
return imediapixel_pagelist($parent_page,$num,$orderby,$style);
}
add_shortcode('pagelist','imediapixel_pagelist_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment