我通常有一个画廊。我想显示一个随机发布的帖子中的随机图像及其标题,这可能会导致帖子下面出现类似permalink的相关帖子。
我使用了以下代码:
<?php
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => 3,
\'post_status\' => null,
\'post_parent\' => get_the_ID(),
\'post_mime_type\' => \'image\',
\'orderby\' => \'rand\'
);
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo apply_filters( \'the_title\' , $attachment->post_title );
the_attachment_link( $attachment->ID , false );
}
}
它显示未从媒体库发布的图像附件。并将url显示为/wp内容/上传/2013/01/附件名称不作为abc。com/帖子名/附件名。请建议!!
谢谢