Created
February 2, 2021 12:50
-
-
Save santanup789/928ffdad1b6c77122df31378586e7374 to your computer and use it in GitHub Desktop.
Get child pages of the current page, similarly get details of siblings of a child page along with the details of their parent page in a child page.
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 | |
global $post; | |
$args = array( | |
'post_type' => 'page', //write slug of post type | |
'posts_per_page' => -1, | |
'post_parent' => $post->ID, //place here id of your parent page | |
'order' => 'ASC', | |
'orderby' => 'menu_order', | |
); | |
$the_query = new WP_Query( $args ); | |
if ( $the_query->have_posts() ) { | |
echo "<div class='animal_health_welfare_topics'><div class='elementor-row'>"; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
$getTitle= get_the_title(); | |
$postURL= get_permalink(); | |
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' ); | |
$url = $src[0]; | |
$excerpt = get_the_excerpt(); | |
$excerpt = substr($excerpt, 0, 150); | |
$excerpt = substr($excerpt, 0, strrpos($excerpt, ' ')); | |
echo "<div class='topic elementor-column elementor-col-50 '>"; | |
echo "<div class='img_box'><a href='$postURL'><img src='$url'></a></div>"; | |
echo "<div class='topic_data'><a href='$postURL' class='title'><h3>$getTitle</h3></a><p>$excerpt ...</p><a href='$postURL' class='readMoreBtn style_2'>Read More</a></div>"; | |
echo "</div>"; | |
} | |
echo "</div></div>"; | |
} | |
else { | |
if ( $post->post_parent ) { | |
echo "<div class='animal_health_welfare_topics'><div class='elementor-row'>"; | |
$parentpost = get_post($post->post_parent); | |
$parentImgsrc = wp_get_attachment_image_src( get_post_thumbnail_id($post->post_parent), 'medium' ); | |
$parenttitle = $parentpost->post_title; | |
$parentImgurl = $parentImgsrc[0]; | |
$parentpostURL = get_permalink($parentpost); | |
$parentexcerpt = $parentpost->post_excerpt; | |
$parentexcerpt = substr($parentexcerpt, 0, 150); | |
$parentexcerpt = substr($parentexcerpt, 0, strrpos($parentexcerpt, ' ')); | |
echo "<div class='topic elementor-column elementor-col-50 '>"; | |
echo "<div class='img_box'><a href='$parentpostURL'><img src='$parentImgurl'></a></div>"; | |
echo "<div class='topic_data'><a href='$parentpostURL' class='title'><h3>$parenttitle</h3></a><p>$parentexcerpt ...</p><a href='$parentpostURL' class='readMoreBtn style_2'>Read More</a></div>"; | |
echo "</div>"; | |
$siblings = new WP_Query( array( | |
'post_type' => 'page', | |
'post_parent' => $post->post_parent, | |
'post__not_in' => array( $post->ID ), | |
'order' => 'ASC', | |
'orderby' => 'menu_order', | |
'post_parent__in' => array( $post->post_parent ), | |
) ); | |
if ( $siblings->have_posts() ) { | |
while ( $siblings->have_posts() ) { | |
$siblings->the_post(); | |
$getTitle= get_the_title(); | |
$postURL= get_permalink(); | |
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'medium' ); | |
$url = $src[0]; | |
$excerpt = get_the_excerpt(); | |
$excerpt = substr($excerpt, 0, 150); | |
$excerpt = substr($excerpt, 0, strrpos($excerpt, ' ')); | |
echo "<div class='topic elementor-column elementor-col-50 '>"; | |
echo "<div class='img_box'><a href='$postURL'><img src='$url'></a></div>"; | |
echo "<div class='topic_data'><a href='$postURL' class='title'><h3>$getTitle</h3></a><p>$excerpt ...</p><a href='$postURL' class='readMoreBtn style_2'>Read More</a></div>"; | |
echo "</div>"; | |
} | |
} | |
echo "</div></div>"; | |
} | |
} | |
wp_reset_postdata();?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment