php – How do you choose to display specific posts/pages by parent url
I have adjacent posts set up correctly but it’s displaying all of the posts/pages. I need it to show specific ones. The easiest way would be by parent URL if that’s possible as I need to do this multiple times. So www.example.com/sydney/ would be the URL and every page that uses the sydney parent would be displayed and nothing else.
Many thanks
Danny
ID ) ) {
$prev_post_image_url = wp_get_attachment_image_url( get_post_thumbnail_id( $prev_post->ID ), ‘thumbnail’ );
} else {
$prev_post_image_url=”https://dummyimage.com/150″;
} ?>
<a class="prev-post adjacent-post" href="<?php the_permalink( $prev_post->ID ) ?>">
<img src="<?php echo $prev_post_image_url; ?>" alt="Previous Post" />
<div>
<p class="adjacent-label">← Previous Post</p>
<h4 class="adjacent-title"><?php echo get_the_title( $prev_post->ID ); ?></h4>
</div>
</a>
1,
‘no_found_rows’ => true,
‘order’ => ‘DESC’,
);
$first = new WP_Query( $args );
$first->the_post();
// first post’s image URL
if ( has_post_thumbnail() ) {
$first_post_image_url = wp_get_attachment_image_url( get_post_thumbnail_id(), ‘thumbnail’ );
} else {
$first_post_image_url=”https://dummyimage.com/150″;
} ?>
<a class="prev-post adjacent-post" href="<?php the_permalink() ?>">
<img src="<?php echo $first_post_image_url; ?>" alt="Previous Post" />
<div>
<p class="adjacent-label">← Previous Post</p>
<h4 class="adjacent-title"><?php echo get_the_title(); ?></h4>
</div>
</a>
<?php wp_reset_postdata();
}
// Next post if present, otherwise the very last post.
$next_post = get_adjacent_post( false, ”, false );
if ( $next_post ) { // next post
if ( has_post_thumbnail( $next_post->ID ) ) {
$next_post_image_url = wp_get_attachment_image_url( get_post_thumbnail_id( $next_post->ID ), ‘thumbnail’ );
} else {
$next_post_image_url=”https://dummyimage.com/150″;
} ?>
<a class="next-post adjacent-post" href="<?php the_permalink( $next_post->ID ) ?>">
<img src="<?php echo $next_post_image_url; ?>" alt="Next Post" />
<div>
<p class="adjacent-label">Next Post →</p>
<h4 class="adjacent-title"><?php echo get_the_title( $next_post->ID ); ?></h4>
</div>
</a>
1,
‘no_found_rows’ => true,
‘order’ => ‘ASC’,
);
$last = new WP_Query( $args );
$last->the_post();
// last post’s image URL
if ( has_post_thumbnail() ) {
$last_post_image_url = wp_get_attachment_image_url( get_post_thumbnail_id(), ‘thumbnail’ );
} else {
$last_post_image_url=”https://dummyimage.com/150″;
} ?>
<a class="next-post adjacent-post" href="<?php the_permalink() ?>">
<img src="<?php echo $last_post_image_url; ?>" alt="Next Post" />
<div>
<p class="adjacent-label">Next Post →</p>
<h4 class="adjacent-title"><?php echo get_the_title(); ?></h4>
</div>
</a>
<?php wp_reset_postdata();
}
?>
Leave an answer