0

我目前正在尝试在水平滑块中显示我的帖子的特色图片,该滑块同时显示三张图片,然后单击下三个(右/左),但是我无法显示特色图片。

我的代码:

    <div id="primary">
        <div id="content" role="main">
        <?php while ( have_posts() ) : the_post(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class('collections'); ?>>
                <header class="entry-header">
                    <h1 class="entry-title">Collections</h1>
                </header>
                <div class="entry-content">
                    <div class="images" >
                        <a href="#" class="arrow prev" ></a>
                        <a href="#" class="arrow next"></a>
                        <div class="wrap"  >
                            <?php 
                            $url = get_permalink();
                            $images = the_post_thumbnail();
                            $count = is_array($images) ? count($images) : 0;
                            if($count)
                            {   
                                $n = 0;                         //$images[$i]['url']
                                for ($i = 0; $i < $count; $i++)
                                {
                                    $l = $i * 100;
                                    $t = $i * -300;
                                    $big = image_downsize($images[$i]['id'], 'full');
                                    $medium = image_downsize($images[$i]['id'], 'medium');
                                    echo '<a href="', $url,'" 
                                    class=" '.(($n==0)?'n':'').' image-holder"  '.(($n==0)?'id="n'.$i.'"':'').'><img src="',$big[0],'"
                                     class="image"   /></a>';
                                    if($n < 2)
                                    $n++ ;
                                    else
                                    $n = 0;
                                }
                            }
                            ?>
                            <div style="clear:both"></div>
                        </div>
                    </div>
                </div>
            </article>
        <?php endwhile; // end of the loop. ?>
        </div>
    </div>

如果有人可以帮助我解决这个问题,将不胜感激。

4

1 回答 1

3

每个帖子/页面只有一张特色图片,您可以使用

if ( has_post_thumbnail() ) {
    the_post_thumbnail();
}

这个函数直接打印图像(一个 img 标签)并且get_the_post_thumbnail()函数返回一个图像,所以你必须回显它。您的代码和问题令人困惑,因为您不能为单个帖子/页面提供三个特色图像,但可以将多个图像附加到帖子/页面。如果您尝试获取所有图像,那么您可以查看以下文章。

  1. 在 WordPress 中显示附加到帖子的所有图像
  2. 显示附加到没有插件的帖子的所有图像
于 2013-05-24T16:36:22.900 回答