• Hi all-

    I am trying to create a box on the front-page that simply displays an image which links to the single post page.

    I have read the Codex and added this code to my functions.php page:

    <?php
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 296, 152, true );
    ?>

    And here is my loop that is supposed to be pulling from a single category.

    <div id="art-highlight-container">
      <div id="focus-box3">
        <?php query_posts('category_name=Art-Focus&showposts=1'); ?>
        <?php if ( has_post_thumbnail()) : ?>
          <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
          <?php the_post_thumbnail(); ?>
          </a>
        <?php endif; ?>
      </div><!-- div#focus-box3 -->
    </div><!-- #art-highlight-container -->

    I am unable to display the image in “art-highlight-container”. Any suggestions?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter tripdog

    (@tripdog)

    Oh by the way the site I’m working on is located at: https://aforsay.org/wp

    The art-highlight box is the one directly adjacent to the calendar.

    Thanks.

    t

    Your custom query is not pulling in any posts.

    Try:

    <a href="<?php the_permalink(); ?>"><img src="<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'original'); echo $thumbnail[0];?>" width="296" alt="<?php the_title(); ?>" /></a>

    Thread Starter tripdog

    (@tripdog)

    phe.le thanks a ton. It almost works, but there is now a broken image link.

    This is how I implemented your code example:

    <div id="art-highlight-container">
      <div id="focus-box3">
       <a href="<?php the_permalink(); ?>"><img src="<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'original'); echo $thumbnail[0];?>" width="296" alt="<?php the_title(); ?>" /></a>
      </div><!-- div#focus-box3 -->
    </div><!-- #art-highlight-container -->

    Did I get the implementation wrong?

    Try:

    <div id="art-highlight-container">
      <div id="focus-box3">
        <?php query_posts('category_name=Art-Focus&showposts=1'); ?>
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
         <a href="<?php the_permalink(); ?>"><img src="<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'original'); echo $thumbnail[0];?>" width="296" alt="<?php the_title(); ?>" /></a>
        <?php endwhile; ?>
        <?php endif; ?>
        <?php wp_reset_query(); ?>
      </div><!-- div#focus-box3 -->
    </div><!-- #art-highlight-container -->

    I think you are missing: <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

    Please try again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Featured images do not display.’ is closed to new replies.