我有一些代码可以提取页面上的精选图像,但是如何将链接返回到它来自的原始帖子?
这是我的代码:
<?php
$mypages = get_pages( array() );
$mypages_featured_images = array();
foreach ( $mypages as $mypage ) {
if ( get_the_post_thumbnail( $mypage->ID ) ) {
$mypages_featured_images[] = get_the_post_thumbnail( $mypage->ID );
}
}
?>
<?php
if ( false !== $mypages_featured_images ) {
?>
<ul>
<?php
foreach ( $mypages_featured_images as $featured_image ) {
echo '<li>' . $featured_image . '</li>';
}
?>
</ul>
<?php
}
?>
理想情况下,我想将带有链接的标题放回到图像所在的帖子。
提前致谢
答案 0 :(得分:1)
为什么不简化一切?根本不需要第二个循环...
<?php
$mypages = get_pages( array() );
if ( $mypages ) {
echo '<ul>';
foreach ( $mypages as $mypage ) {
if ( get_the_post_thumbnail( $mypage->ID ) ) {
echo '<li><a href="' . get_permalink( $mypage->ID ) . '">' . get_the_post_thumbnail( $mypage->ID ) . '</a></li>';
}
}
echo '</ul>';
}
?>