私のWordpressサイトで次のコードを使用しています。ショートコードは、現在のページのサブページを見つけて、タイトルと抜粋を返します。ページのサムネイルを統合しようとしていますが、親ページの投稿のサムネイルを返しています。何か案は?
add_shortcode("children-excerpt", "sc_show_children_excerpt");
function sc_show_children_excerpt($atts, $content = null){
if($atts['length'] > 0 ){
//maybe set a minimum length here
}else{
$atts['length'] = 50;
}
if(isset($atts['id']) && is_numeric($atts['id'])){
//id specified by shortcode attribute
$parent_id = $atts['id'];
}else{
//get the id of the current article that is calling the shortcode
$parent_id = get_the_ID();
}
$output = "";
$i = 0;
if ( $children = get_children(array(
'post_parent' => $parent_id,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'page')))
{
foreach( $children as $child ) {
$title = $child->post_title;
$child_excerpt = apply_filters('the_excerpt', $child->post_excerpt);
//split excerpt into array for processing
$words = explode(' ', $child_excerpt);
//chop off the excerpt based on the atts->lenth
$words = array_slice($words, 0, $atts['length']);
//merge the array of words for the excerpt back into sentances
$child_excerpt = implode(' ', $words);
$link = get_permalink($child->ID);
$test = wp_get_attachment_image_src( $post->ID, 'thumbnail' );
$image_id = get_post_thumbnail_id($post->ID);
$image_url = wp_get_attachment_image_src($image_id,'medium');
$image_url = $image_url[0];
$result = '<img src="'.$image_url.'" class="alignleft" />';
$output .= "<div class='attorney'>";
$output .= $result;
$output .= "<a href='$link'>$title</a>";
$output .= "<p>". $child_excerpt ."</p>";
$output .= "</div><div class='clear'></div>";
}
}
return $output;
}