【发布时间】:2015-06-06 22:53:27
【问题描述】:
我有一个网页,我想展示某个作者上传的图片。
如果我查看媒体,在后端,每张图片都有一个“上传者”属性,然后是作者姓名。
我试过使用这个循环:
<?php
// The Query
$args = array(
'author' => $author_name_variable, // Replace with author id
'post_status' => 'any',
'post_type' => 'attachment'
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . the_content() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
这是非常错误的。有些作者会显示每个媒体文件,有些则不显示;其余的都是不准确的。这是一个真正的盲目射击:/
目标是遍历所有媒体文件,然后将所有文件的the_content() 发布为具有相应的上传者名称。
【问题讨论】:
标签: php wordpress loops gallery author