我有一个页面(公司)有两个子页面(新的,特色的) 子页面从自定义后期类型(公司)查询内容。在子页面中还有一个搜索框,用于过滤自定义帖子类型中的内容 然后,有一个横幅读取页面“公司”的缩略图,该横幅也应该在子页面中可见。我写了这个函数,它适用于两个子页面,但不适用于搜索结果。它用第一个结果的后缩略图代替横幅,而不是超级父母(公司) 我该如何解决这个问题?。
function get_parent_post_thumb( $post ){
if ( $post->post_parent ) {
$parentId = end( $post->ancestors );
echo get_the_post_thumbnail( $parentId, 'banner' );
} else {
the_post_thumbnail( $post->ID, 'banner' );
}
}
修改
我使用了不同的方法,但不是动态的...我只是在搜索表单中放入一个带有父ID的空字段,然后在search.php
模板中检索它。
<input type="hidden" name="parentId" value="129" />
然后......
<?php
$id = $_GET['parentId'];
echo get_the_post_thumbnail($id, 'banner');
?>
这不太理想,但它有效。有没有人知道如何使用我在原始问题中发布的功能来做到这一点?