Hi, ich möchte gerne das erste Bild eines Artikels auf der Startseite auslesen. Habe nun folgenden Code in meine index.php eingefügt, aber nichts passiert:
PHP
<?php
function get_attached_images(){
// This function runs in "the_loop", you could run this out of the loop but
// you would need to change this to $post = $valid_post or something other than
// using the global post declaration.
global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$attachment = get_posts($args); // Get attachment
if ($attachment) {
$img = wp_get_attachment_image_src($attachment[0]->ID, $size = 'full'); ?>
<img alt="<?php the_title(); ?>" src="<?php echo $img[0] ; ?>" width="<?php echo $img[1] ?>" height="<?php echo $img[2] ?>"/>
<?php }
}
?>
Alles anzeigen
Kann mir hier jemand weiterhelfen? Vielen Dank!