現在wordpressでサイトを作成しています、functions.phpに下記のように、記事内の最初の画像を取り出すように書いています。
これに、条件を追加して、
/emoticons/というディレクトリに入っている画像は除外したいのですが、どのように書けばいいでしょうか。
詳しい方、よろしくお願い致します。
function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all("/<img[^>]+src=[\"'](s?https?:\/\/[\-_\.!~\*'()a-z0-9;\/\?:@&=\+\$,%#]+\.(jpg|jpeg|png|gif))[\"'][^>]+>/i", $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/img/noimg.gif"; } return $first_img; }
回答2件
あなたの回答
tips
プレビュー