谁能帮我开发一个wordpress脚本,如果它不存在,它将获得第一个附加(上传)的图像。
Theoretically:[如果存在]
<img src="<?php echo catch_that_image() ?>" />
[或其他]<img src="\'. wp_get_attachment_url($attachment->ID) . \'" alt="Main Image" id="mainImage"" />
[或其他]<img src="<?php bloginfo(\'template_url\') ?>/images/default.png" />
My current code looks like this (UPDATED.. AGAIN)
<?php
$args = array(
\'post_parent\' => $post->ID,
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'offset\' => \'0\',
\'numberposts\' => 1
);
$attachments = get_posts($args);
$images =& get_children( \'post_type=attachment&post_mime_type=image&post_parent=\' . $post->ID );
if ($attachments) {
foreach ($attachments as $attachment) {
if(wp_attachment_is_image( $attachment->ID )) {
echo \'<img src="\'. wp_get_attachment_url($attachment->ID) . \'" alt="Main Image" id="mainImage"" />\'; }}}
<!-- else if ( count( $images ) > 0 ) echo get_the_post_thumbnail; } -->
else {
echo \'<img src="http://hellotokyostore.com/wp-content/themes/hellotokyo/images/default.png" alt="Hello Tokyo" />\'; }
?>