• I have a problem, please help me.

    I have a function in my function.php, it sets the first image from the post and display it, like this:

    function get_imageurl_from_text($text) {
    	preg_match('/<img.+?src=\"(.+?)\b\"/is', stripslashes($text), $match);
    	if(strlen($match[1])) {
    		return $match[1];
    	}
    	else {
    	return get_template_directory_uri() . "/images/no_image.jpg";
    	}
    }

    I used it to display post at my homepage. And now, I only want to display the post which has photo (one or more photos) at my headline. The post has no image don’t display.

    Please help me for my problem. Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dctrkmhp

    (@dctrkmhp)

    Or please share me the code which only display the post has photo, not show post has no image.

    Hi dctrkmhp, WordPress has a built in functionality called Featured Images (also known as Post Thumbnails). You could enable post thumbnails, and have those display instead of the first image from your post. Featured Images have a built in conditional check so you could do something like: if ( has_post_thumbnail() ):

    See here for more details:
    http://codex.wordpress.org/Post_Thumbnails

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Only display post which has a photo’ is closed to new replies.