WordPress.org

Ready to get started?Download WordPress

Forums

Make featured images on news page clickable (7 posts)

  1. maria.darron
    Member
    Posted 1 month ago #

    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(); ?>
  2. wpmultiverse
    Member
    Posted 1 month ago #

    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.

  3. maria.darron
    Member
    Posted 1 month ago #

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

  4. maria.darron
    Member
    Posted 1 month ago #

    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.

  5. maria.darron
    Member
    Posted 1 month ago #

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

  6. maria.darron
    Member
    Posted 1 month ago #

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

  7. Evan Herman
    Member
    Posted 1 month ago #

    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

Reply

You must log in to post.

About this Topic