For some reason the data-mainsrc
attribute isn’t outputting anything. I’m trying to get it to output the image url.
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'home-thumb' );$url = $thumb['0']; ?>
Did I format the code incorrectly?
Full code
<!-- Start the loop -->
<?php $home_query = new WP_Query('post_type=projects');
while($home_query->have_posts()) : $home_query->the_post(); ?>
<article class="project">
<img width="375" height="375" src="<?php bloginfo( 'template_url' ); ?>/img/loading.gif" data-mainsrc="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'home-thumb' );$url = $thumb['0']; ?>" class="attachment-home-thumb" alt="<?php the_title(); ?>">
<div class="overlay">
<a class="post-link expand" href="#" rel="<?php the_ID(); ?>">+</a>
</div>
</article>
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
</div><!-- #projects-list -->
you are not echoing anything, just storing in a variable, so this
probably ends up looking like this once it is evaluated by php
data-mainsrc=""
The functions that start with
get_
… only return a value, unlike the functions that start withthe_
… whichecho
it.so how about this