脚本宝典收集整理的这篇文章主要介绍了php – 如何以递归方式将特色图像应用于WordPress中的子页面?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
function get_featured_recursive($post) { if (has_post_thumbnail( $post->ID ) ) { return $post->ID; } else if (!has_post_thumbnail($post->ID) && $post->post_parent != 0) { $parent = get_post($post->post_parent); if (has_post_thumbnail($parent->ID)){ return $parent->ID; } } else if(!has_post_thumbnail($parent->ID) && $parent->post_parent != 0){ get_featured_recursive(get_post($parent->post_parent)); } else if(!has_post_thumbnail($parent->ID) && $parent->post_parent == 0 ) { return null; } }
然后在您的模板中使用它来显示特色图像:
< ?PHP $featured_image_post = get_featured_recursive($post); if ($featured_image_post != null) : $featured_image_src = wp_get_attachment_image_src(get_post_thumbnail_id($featured_image_post),'single-post-thumbnail'); ?>
以上是脚本宝典为你收集整理的php – 如何以递归方式将特色图像应用于WordPress中的子页面?全部内容,希望文章能够帮你解决php – 如何以递归方式将特色图像应用于WordPress中的子页面?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。