如何在 wordpress 帖子中创建指向第一个图像附件页面的文本链接,而不试图弄清楚发布后的 slug 是什么。我意识到我可以将图像链接到他们的附件页面,但我无法创建文本链接。这可能吗?
问问题
1579 次
1 回答
3
弄清楚了:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'offset' => 0,
'orderby' => 'menu_order',
'order' => 'asc',
'post_status' => null,
'post_parent' => $post->ID,
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
if(wp_attachment_is_image( $attachment->ID )) {
echo '<a href="'. get_attachment_link($attachment->ID) . '">LINK TEXT HERE</a>';
break;
}
}
}
?>
于 2010-12-20T19:07:27.540 回答