Wordpress在主页上显示特色图片,用于博客摘录/链接

时间:2020-04-11 00:23:53

标签: php wordpress

我希望显示博客文章的Wordpress特色图像以及博客文章的摘要和标题(已经存在)。我们通常不会在PHP中工作,因此在显示图片时遇到了问题。这是针对客户的网站而言,结果证明比我们预期的要多得多。该代码最初是从他们称为“活动”的部分中提取图像。我们不再使用该内容,而是再次使用“帖子”部分。

该区域的代码如下。任何帮助是极大的赞赏。谢谢

   <?php
   $args = array('post_type' => 'post','order'=> 'ASC', 'posts_per_page' =>2,'orderby' => 'date','order'=>'DESC');
       // The Query
       query_posts( $args );?>
       <ul>

        <?php while ( have_posts() ) : the_post(); ?>
        <?php //$post_thumbnail_id = get_post_thumbnail_id( get_the_ID () ); ?> 
        <?php /*$image_id = get_post_thumbnail_id(get_the_ID ());
              $image_url = wp_get_attachment_image_src($image_id,'post-thumb', true);*/
             ?>

      <li>
         <?php //if ( has_post_thumbnail() ){  ?>
         <?php if(get_field('show_this_activity_image_in_home_page')){?>
         <div class="actImg">

    <?php
            $attachment_id = get_field('show_this_activity_image_in_home_page');
                    $size = "post-thumb"; // (thumbnail, medium, large, full or custom size)
                    $image = wp_get_attachment_image_src( $attachment_id, $size );

1 个答案:

答案 0 :(得分:0)

好的,代码看起来像是在使用“高级自定义字段”一样,该字段本来会返回媒体项的ID。当您从“自定义帖子类型”转移到本机帖子时,这些ACF值将不再可用。

使用the_post();设置发布数据后,您应该可以使用get_the_post_thumbnail_url();来获取缩略图网址

有关此功能的说明,请参见https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

相关问题