Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to display a title, featured image, and content from a page into a new template (that will contain content from several pages). I tried to just echo the variables as shown below, but right now it's only display the content and title+"array". Any ideas?

Here is my current array:

 <?php
 $id = 2131;
 $post = get_page($id);
 $content = apply_filters('the_content', $post->post_content);
 $title = $post->post_title;
 $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'single-post-    
 thumbnail' );
 echo $content;
 echo $title;
 echo $image;
?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

wp_get_attachment_image_src returns an array, not a single value. Please refer to this article for more info: wordpress.org/Function_Reference/wp_get_attachment_image_src

Default Usage

<?php 
$attachment_id = 8; // attachment ID

$image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
?> 

<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
share|improve this answer
    
That makes sense, but I'm confused what the syntax would look like to just return the image in an image tag from my original array? –  mtthwbsh Feb 20 '13 at 1:21
    
@mtthwbsh Try this: echo $image[0]; –  Josh Mountain Feb 20 '13 at 2:26
    
Worked perfect, thanks! –  mtthwbsh Feb 20 '13 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.