배열의 각 이미지에 대해 별도의 og : image 메타 태그를 출력하는 코드 스 니펫을 얻으려고하면 문제가 있습니다.Facebook 메타 태그 PHP 상태
<?php 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 = "http://example.com/images/fbthumb.jpg";
}
return $first_img;
}
?>
현재 코드는 첫 번째 일치의 img src에 태그를 반환하지만 사용하는 공유 이미지를 선택할 수 있도록 나는 그것이 별도의 태그로 모두를 반환하고 싶습니다.
$first_img = $matches [1] [0];
가 필요
각 조건의 몇 가지 유형으로 변경하지만 어떻게 임 확실하지 될 :나는이 줄을 알고있다. 어떤 도움이라도 대단히 감사하겠습니다. 감사!
편집 :
여기있는 마지막 제안 후 내 코드 :
<?php function catch_that_image() {
global $post, $posts;
$result = preg_match_all('#<img.+src=[\'"]([^\'"]+)[^>]*>#i', $post->post_content, $matches);
return $matches[1];
}
>
"출력 />
나는 여전히 질수 그림을? 어떤 아이디어?
' * * # i', $ post-> post_content, $ matches); foreach ($ matches [1] as $ match) { $ imgSources [] = $ match; } return $ imgSources; } > <메타 속성 = "OG : 이미지"내용 = " PHP 경우 (function_exists ('catch_that_image')) {에코 catch_that_image()}>?"/> ' –
brianr1