【问题标题】:How to make a recent post carousel in Wordpress如何在 Wordpress 中制作最近的帖子轮播
【发布时间】:2017-02-18 08:53:10
【问题描述】:

我需要使用 PHP 和 BxSlider 在 Wordpress 中制作一个最近发布的轮播,但我无法让它显示缩略图。

我有最近的帖子,下一个代码:

    <?php
    $recent_posts = wp_get_recent_posts();
    foreach( $recent_posts as $recent ){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </li> ';
    }
    wp_reset_query();
    ?>

此代码显示了上一篇文章并且运行良好,但是如何从媒体库中获取特色图像或缩略图或图像?

【问题讨论】:

    标签: php wordpress post thumbnails bxslider


    【解决方案1】:

    试试这个 -

    <?php
    $args = array(
        'numberposts' => 10, //number of post.
        'post_type' => 'post',
        'post_status' => 'publish'
    );
    $recent_posts = wp_get_recent_posts();
    foreach( $recent_posts as $recent ){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .get_the_post_thumbnail( $recent["ID"], 'thumbnail' ).   $recent["post_title"].'</a> </li> ';
    }
    wp_reset_query();
    ?>
    

    【讨论】:

      【解决方案2】:

      你试过这些吗?

      get_the_post_thumbnail( $post_id, 'thumbnail' );      // Thumbnail (Note: different to Post Thumbnail)
      get_the_post_thumbnail( $post_id, 'medium' );         // Medium resolution
      get_the_post_thumbnail( $post_id, 'large' );          // Large resolution
      get_the_post_thumbnail( $post_id, 'full' );           // Original resolution
      

      https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/

      还是这个?

      //Default WordPress
      the_post_thumbnail( 'thumbnail' );     // Thumbnail (150 x 150 hard cropped)
      the_post_thumbnail( 'medium' );        // Medium resolution (300 x 300 max height 300px)
      the_post_thumbnail( 'medium_large' );  // Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
      the_post_thumbnail( 'large' );         // Large resolution (1024 x 1024 max height 1024px)
      the_post_thumbnail( 'full' );          // Full resolution (original size uploaded)
      

      https://developer.wordpress.org/reference/functions/the_post_thumbnail/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-25
        • 1970-01-01
        • 2019-03-18
        • 1970-01-01
        • 2019-08-18
        • 1970-01-01
        • 2021-11-03
        相关资源
        最近更新 更多