我使用此代码通过作者函数发布相关帖子:
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 10 ) );
$output = '<div class="block">';
foreach ( $authors_posts as $authors_post ) {
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
$output .= '</div>';
return $output; }
要输出,我在single.php文件的循环中使用以下代码:
<?php echo get_related_author_posts(); ?>
目前它显示的功能仅将标题发布为链接。
如何通过作者功能查看此wp代码以显示此相关帖子的缩略图?
答案 0 :(得分:0)
尝试:
foreach ( $authors_posts as $authors_post ) {
$output .= get_the_post_thumbnail($authors_post->ID);
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
$output .= '</div>';
检查get_the_post_thumbnail以获取更多信息,例如图片大小和额外课程等属性 如果您需要更多帮助,请告诉我。