nickyfsh
nickyfsh

Reputation: 175

wordpress display featured image

I am currently trying to display my post's featured image in a horizontal slider that shows three images at the time, and then the next three once clicked (right / left), however I can not get the featured images to show up.

My code:

    <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>

It would be greatly appreciated if someone can help me figure this out.

Upvotes: 0

Views: 13698

Answers (1)

The Alpha
The Alpha

Reputation: 146191

Featured image is only one per post/page and you can get it using

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

This function directly prints the image (an img tag) and get_the_post_thumbnail() function returns an image so you have to echo it. Your code and question is confusing because you can't have three featured images for a single post/page but can have multiple images attached to a post/page. if you are trying to get all images then you can check following articles.

  1. Display All Images Attached to a Post in WordPress.
  2. display all images attached to a post without a plugin.

Upvotes: 3

Related Questions