function to show only featured image of the posts

The problem is whenever I display a post containing gallery, it shows them all on front page same as within post. I want a function for posts on front page to display only the clickable featured image with read more below for posts have predefined featured image. And if the post has some specific category eg. video, it should just display video and below some sharing buttons.

This is what I achieved till now, being a newbie can’t move further

Read More
 function insertfeaturedimage($content) {
global $post;

if ( current_theme_supports( 'post-thumbnails' ) ) {

    if (is_page() || is_single() || is_front_page()) {
        $content = the_post_thumbnail('page-single');
        $content .= $original_content;

    }

 }
 return $content;
}

add_filter( 'the_content', 'InsertFeaturedImage' ); 

I want the above functionality to above function.

Any help appreciated.

Related posts

Leave a Reply

1 comment

  1. I am not sure that a filter on the_content is the way to go here. If I understand you, I think that all you need is something like the following your theme– cribbed from the two Codex pages listed below and altered slightly.

    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail();
      echo '<a class="moretag" href="'. get_permalink($post) . '"> Read the full article...</a>';
    } else { 
      the_content();
    }
    

    That may not look right since I don’t know what your theme code looks like but that it the idea.

    If you are going to filter the_content I think what you want is more like this:

    function insertfeaturedimage($content) {
        global $post;
        if ( current_theme_supports( 'post-thumbnails' ) ) {
            if (is_page() || is_single() || is_front_page()) {
                $thumb = get_the_post_thumbnail('page-single');
                if (!empty($thumb)) {
                    $content = $thumb.'<a class="moretag" href="'. get_permalink($post) . '"> Read the full article...</a>';
                }
            }
         }
         return $content;
    }
    add_filter( 'the_content', 'InsertFeaturedImage' );
    

    Note: I used get_permalink($post); instead of get_permalink($post->ID); on purpose. Despite the docs, get_permalink will accept the $post object itself and if given the object won’t run get_post. You can save a query (under some circumstances anyway).

    http://codex.wordpress.org/Function_Reference/the_post_thumbnail

    http://codex.wordpress.org/Customizing_the_Read_More