1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); }
function post_thumbnail_src() { global $post; if ($values = get_post_custom_values("thumb")) { $post_thumbnail_src = $values[0]; } elseif (has_post_thumbnail()) { $thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); $post_thumbnail_src = $thumbnail_src[0]; } else { $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $post_thumbnail_src = $matches[1][0] ?? ''; if (empty($post_thumbnail_src)) { $random = mt_rand(1, 10); $post_thumbnail_src = get_bloginfo('template_url') . "/images/pic/{$random}.jpg"; } } echo $post_thumbnail_src;
|