Child Post

foreach ($services_posts as $service_data) {

$args = array(
‘sort_column’     => ‘menu_order’,
‘numberposts’     => 100,
‘orderby’         => ‘post_date’,
‘order’           => ‘DESC’,
‘post_type’       => ‘services’,
‘parent’          => $service_data->ID,
‘hierarchical’      => true,
‘child_of’          => $service_data->ID,
‘post_status’     => ‘publish’ );
$child_posts=get_pages( $args );

$permalink = get_permalink($service_data->ID);
echo ‘<li><a href=’;

if(!empty($child_posts))
echo get_permalink($child_posts[0]->ID);
else
echo get_permalink($service_data->ID);

echo ‘>’.$service_data->post_title.”</a>”;

if(!empty($child_posts)) {
echo ‘<ul>’;
foreach ($child_posts as $child_post) {
$permalink = get_permalink($child_post->ID);
echo ‘<li style=”width: 230px;”><a href=’.get_permalink($child_post->ID).’>’.$child_post->post_title.”</a></li>”;
}
echo ‘</ul>’;
}
echo ‘</li>’;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: