Okay, a couple of things – first I would suggest modifying your main query to grab the thumbnail ID at the same time (I have also changed it to only get posts that have a thumb):
$sql = "SELECT wp_posts.*, meta_value AS thumbnail_id FROM wp_posts " .
"LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id " .
"WHERE post_type="post" AND meta_key = '_thumbnail_id' AND meta_value != '' " .
"ORDER BY post_date ASC";
Now for the processing:
while ( $linha = $stmt->fetch ( PDO::FETCH_OBJ ) ) {
$meta = $pdo->prepare( 'SELECT meta_value FROM wp_postmeta WHERE meta_key = "_wp_attachment_metadata" AND post_id = ?' );
$meta->execute( array( $linha->thumbnail_id ) );
$file = null; // Failsafe in case anything below fails
if ( $data = $meta->fetchColumn() ) {
if ( $data =@ unserialize( $data ) ) {
$file = $data['file'];
if ( ! empty( $data['sizes'] ) ) {
$sizes = $data['sizes'];
if ( ! empty( $sizes['magento-image'] ) )
$file = $sizes['magento-image']['file'];
elseif ( ! empty( $sizes['thumbnail'] ) ) // You might want to fallback, up to you
$file = $sizes['thumbnail']['file'];
}
if ( $file !== $data['file'] ) {
// Files stored in sizes are only the basename
// If you use year/month uploads, we need to grab that path
if ( '.' !== $path = dirname( $data['file'] ) )
$file = "$path/$file";
}
}
}
if ( $file ) {
// Gotcha!
echo "<img src="http://example.com/wp-content/uploads/$file" />";
}
}
This code is not tested, so see how you go and report back with any errors.