WordPress.org

Support

Support » How-To and Troubleshooting » Make featured images on news page clickable

Make featured images on news page clickable

  • Hi, I’m looking to make the featured images on my blog posts clickable, so they’ll link directly to the full sized image file.

    I know there would be a small tweak to add to “category_news.php”, though I’m not too familiar with javascript. The full .php file is below. Any help would be much appreciated. Thank you!

    http://marylyndintenfass.com/news/

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    	<div id="right-col" class="news_blog">
    
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="entry-content">
    
    <?php
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail();
    }
    ?>
    
    <div class="entry-text">
    <!-- <h2 class="entry-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>-->
    
    <h2 class="entry-title"><?php the_title(); ?></h2>
    
       <?php the_content(); ?>
    
    </div>
    
     </div> <!-- closes the first div box -->
    
     <div style="height: 0px; width: 100%; clear: both; padding: 0; margin: 0;"></div>
    
     <?php endwhile; else: ?>
    
     <p>Sorry, no posts matched your criteria.</p>
    
     <!-- REALLY stop The Loop. -->
     <?php endif; ?>
    
    <?php get_footer(); ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hey there, you can make your featured images link to a larger image by replacing the following in the code you provided above.

    <?php
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail();
    }
    ?>

    with

    <?php
     if ( has_post_thumbnail()) {
       $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
       echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
       the_post_thumbnail('thumbnail');
       echo '</a>';
     }
     ?>

    Hope that helps.

    That worked, thanks! Only now the thumbnails are only 45px x 45px… any way to make them larger?

    Scratch that… I was able to update the thumbnail sizes. But the new script only works when I’m logged into WordPress, and not on the public site. Let me know what I can do… thanks again.

    Scratch that again, fixed the issue. Thank you for your help!!!

    ** What would I have to change to make the images open in a new tab/window? Thanks!!!

    add a target parameter to your anchor tag.

    ie:

    <a href="http://www.google.com" target="_blank">Link</a>

    the target=”_blank” forces the link to open in a new tab.

    -Evan

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Make featured images on news page clickable’ is closed to new replies.
Skip to toolbar