Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

 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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
thanks, it worked wonderful –  10wtaylor Dec 27 '12 at 11:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.