I am focusing on a brand new Wordpress theme the default index view shows the excerpts of latest posts. Some posts is going to be regarding file downloads, and can include a picture, description, and connect to the place that the referred to files are located. The pictures for these kinds of posts is going to be moored with links(other kinds of posts could have images that aren't linked).

For these kinds of posts, I'd like the pictures to connect to their entry's full publish sights(single.php) when displayed in excerpts, as well as the same images to connect to an exterior download link when displayed included in the full publish view.

I am unsure exactly how I'd accomplish this. Any help could be greatly appreciated!

Because I do not have publish pictures defined, and also, since posts might contain multiple images, I wound up doing the work by doing this:

I switched off tags in excerpts(I'd an excerpt wordpress plugin enabling tags in excerpt), i quickly added the next towards the function.php file:

function catch_that_image() {  
    global $post, $posts;  

    $first_img = '';  ob_start();  
    ob_end_clean();  

    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', 


    $post->post_content, $matches);  

    $first_img = $matches [1] [0];  
    if(empty($first_img)){ 
    //Defines a default image    
    $first_img = "/images/default.jpg";  }  
    return $first_img;}

I Quickly added the next towards the primary index template file among the posts title and also the excerpt/content:

<p><a href="<?php the_permalink() ?>" alt="<?php _e('Read full article', 'theme');?>" title="<?php _e('Read full article', 'theme');?>"><img src="<?php echo catch_that_image() ?>"></a></p>    

Random note: It's covered with a

for styling reasons.

Thanks again for guiding me within the right direction.

in case your theme uses 'the_excerpt()' for that top of the page, I believe you can include a filter in functions.php, with a regexp alter the link href in the download connect to the permalink.

something similar to,

function replace_link($content) {
   if (is_home())
      return preg_replace('regular_expression', get_permalink(), $content);
   else
      return $content;
}
add_filter('the_excerpt', 'replace_link');

I can not create a real regular expression not understanding what your download link appears like