我正在尝试显示所有作者以及以下数据:头像,名称,公司名称(自定义元字段),描述和指向其作者页面的链接。输出HTML将是
<img src="">
<p>Name</p>
<p>Company Name</p>
<p>Description</p>
<p><a href="">Link to author page</a></p>
到目前为止,它已接近但未按预期工作。一半的数据在div之外返回。有什么想法吗?
<?php
$authors = wp_list_authors();
if ($authors) {
foreach ($authors as $author) {
$user = get_userdata($author->user_id);
echo get_avatar( $user->ID, 46 );
echo '<div class="l-four"><p>User ID ' . $user->ID . ' '
. $user->user_firstname . ' '
. $user->user_lastname . ' '
. $user->user_url . ' '
. $user->user_description
. '</p>'; ?>
<?php the_author_meta('company', $user->ID);?>
<?php echo '</div>';?><?php
$args=array(
'author' => $user->ID,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
}
}
?>
答案 0 :(得分:1)
尝试稍微不同的代码方法。这使得理解将生成的HTML变得更加容易。正如你所看到的,我没有回应任何HTML,只有PHP。
<?php
$authors = wp_list_authors();
if ($authors) {
foreach ($authors as $author) {
$user = get_userdata($author->user_id);
echo get_avatar( $user->ID, 46 );
?>
<div class="l-four">
<p>User ID: <?php echo $user->ID ?></p>
<p>Firstname: <?php echo $user->user_firstname ?></p>
<p>Lastname: <?php echo $user->user_lastname?></p>
<p>User URL: <?php echo $user->user_url ?></p>
<p>Description: <?php echo $user->user_description ?></p>
<p><?php echo the_author_meta('company', $user->ID); ?></p>
</div>
<?php
$args=array(
'author' => $user->ID,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
}
}
?>