Помогите добавить миниатюру в шордкот

Вопрос решен

Добрый день, подскажите как можно добавить в данный шорткод миниатюру, чтобы она отображалась рядом с названием и датой.

function pu_recent_posts_shortcode($atts, $content = NULL)

{

$atts = shortcode_atts(

[

‘orderby’ =>’date’,

‘posts_per_page’ => ‘5’

], $atts, ‘recent-posts’ );
$query = new WP_Query( $atts );
$output = ‘<ul class=»recent-posts»>’;
while($query->have_posts()) : $query->the_post();

$output .= ‘<li><a href=»‘ . get_permalink() . ‘»>’ . get_the_title() . ‘</a> — <small>’ . get_the_date() . ‘</small></li>’;
endwhile;
wp_reset_query();

return $output . ‘</ul>’;
}

add_shortcode(‘recent-posts’, ‘pu_recent_posts_shortcode’);

 

По умолчанию Вопрос задан в 07.10.2018 в Оптимизация.
Добавить комментарий
1 Ответ (-ов)
    Лучший ответ

    Попробуйте так:

    function pu_recent_posts_shortcode($atts, $content = NULL)
    
    {
    
    $atts = shortcode_atts(
    
    [
    
    ‘orderby’ =>’date’,
    
    ‘posts_per_page’ => ‘5’
    
    ], $atts, ‘recent-posts’ );
    $query = new WP_Query( $atts );
    $output = ‘<ul class=»recent-posts»>’;
    while($query->have_posts()) : $query->the_post();
    
    $output .= ‘<li>‘ . the_post_thumbnail() . ‘<a href=»‘ . get_permalink() . ‘»>’ . get_the_title() . ‘</a> — <small>’ . get_the_date() . ‘</small></li>’;
    endwhile;
    wp_reset_query();
    
    return $output . ‘</ul>’;
    }
    
    add_shortcode(‘recent-posts’, ‘pu_recent_posts_shortcode’);
    

    Но далее Вам придется поиграться с классами  CSS для хорошей визуализации полученной миниатюры

    Специалист Отвечено в 09.10.2018.
    Добавить комментарий

    Ваш ответ

    Размещая свой ответ, вы соглашаетесь с политикой конфиденциальности и условиями предоставления услуг.