Добавить миниатюрное изображение для всех сообщений того же автора в WordPress - PullRequest
0 голосов
/ 10 сентября 2018

Я пытаюсь отобразить все сообщения одного автора в шаблоне single-author.php. В файле functions.php я пытаюсь назвать заголовок и постоянную ссылку. Однако я не могу добавить пост-функцию изображения в вывод. Любые идеи будут полезны. Здесь приведен код functions.php.

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' => 8 ) );

$output = '<ul>';
foreach ( $authors_posts as $authors_post ) {
    $url = wp_get_attachment_url( get_post_thumbnail_id($authors_posts->ID) );
    $output .= '<li style="background: url('. $url.')"><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title,$authors_post->image, $authors_post->ID ) . '</a></li>';
}
$output .= '</ul>';

return $output;
}

Ответы [ 2 ]

0 голосов
/ 11 сентября 2018

Попробуйте, как предложено @ unixmiah

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' => 8 ) );

    $output = '<ul>';
    foreach ( $authors_posts as $authors_post ) {
      $url = get_the_post_thumbnail($authors_posts->ID,'post-thumbnail');
      $output .= '<li style="background: url('. $url.')"><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title,$authors_post->image, $authors_post->ID ) . '</a></li>';
    }
    $output .= '</ul>';

    return $output;
}
0 голосов
/ 10 сентября 2018

Попробуйте с помощью функции ниже

 <?php echo get_the_post_thumbnail($authors_post->ID); ?>
...