Site logo

Archived topic

Let a page automatically adopt the featured image of it's first child

9 replies · Started by Florian on February 14, 2019

Viewing posts 1–10 of 10

I use the following custom post type to redirect certain pages to their first child page. Is it possible to add something so it also adopts the child page's thumbnail? Preferably in a way that it also automatically updates if I ever change it.

<?php
/*
Template Name: Go to first child
*/
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($pagekids) {
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
} else {
// Do whatever templating you want as a fall-back.
}
?>

Hi there,

Looks like that code redirects you to the child page automatically. Wouldn't that child page already have the featured image set?

Yes, but I need the parent to have the same featured image as part 1 because the parent page gets displayed in the sidebar together with its thumbnail.

How are you displaying the parent page in the sidebar?

A plugin displays a random subset of child pages of /tutorials/android
Sometimes these child pages contain single videos -> the thumbnail is displayed
But sometimes these child pages contain their own child pages (because it's a video series with multiple parts), in which case the parent doesn't have a thumbnail on its own.

It would likely need to be an option inside the plugin then, unfortunately. You can check with the developer if such a thing is possible.

So a page can not adopt the thumbnail of another page? I really thought that would be possible.

It can, but it needs to be coded into the output. If you're using a plugin to output the post, the code needs to be inserted into the plugin, or there needs to be a filter available. That's where the plugin author should hopefully be able to help.

Ok thanks, I will contact the plugin author then!

No problem :)

This archived topic is closed to new replies.