Created
June 30, 2011 00:18
-
-
Save miya0001/1055337 to your computer and use it in GitHub Desktop.
list subpages
This file contains 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 | |
/* | |
Plugin Name: List Subpages | |
Author: @miya0001 | |
*/ | |
new listSubpages(); | |
class listSubpages { | |
function __construct() | |
{ | |
add_shortcode('list_subpages', array(&$this, 'shortcode')); | |
} | |
public function shortcode($p) | |
{ | |
if (isset($p['thumbnail']) && $p['thumbnail']) { | |
return $this->blockView($p); | |
} else { | |
return $this->listView($p); | |
} | |
} | |
private function blockView($p) | |
{ | |
$posts = $this->get_posts($p); | |
$size = $p['thumbnail']; | |
$html = '<div class="list_subpages '.$size.'">'; | |
foreach ($posts as $post): | |
$img = get_the_post_thumbnail($post->ID, $size); | |
$url = get_permalink($post->ID); | |
$html .= '<div class="post post-'.$post->ID.'">'; | |
$html .= '<div class="post_thumb"><a href="'.$url.'">'.$img.'</a></div>'; | |
$html .= '<div class="post_content">'; | |
$html .= '<h4><a href="'.$url.'">'.esc_attr($post->post_title).'</a></h4>'; | |
$html .= '<div class="post_excerpt">'.esc_attr($post->post_excerpt).'</div>'; | |
$html .= '</div>'; | |
$html .= '</div>'; | |
endforeach; | |
$html .= '</div>'; | |
return $html; | |
} | |
private function listView($p) | |
{ | |
$posts = $this->get_posts($p); | |
$html = '<ul>'; | |
$list = '<li><a href="%s">%s</a></li>'; | |
foreach ($posts as $p) { | |
$html .= sprintf( | |
$list, | |
get_permalink($p->ID), | |
esc_attr($p->post_title) | |
); | |
} | |
$html .= '</ul>'; | |
return $html; | |
} | |
private function get_posts($p) | |
{ | |
global $post; | |
if( !isset($p['id']) || !strlen($p['id']) ){ | |
$p['id'] = $post->ID; | |
} | |
$args = array( | |
'post_status' => 'publish', | |
'post_type' => 'page', | |
'post_parent' => $p['id'], | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'numberposts' => '-1', | |
); | |
return get_posts($args); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment