This is the problem:
$link = the_permalink();
Replace it with:
$link = get_permalink();
Notice that the WordPress the_*
functions will echo the output, but get_*
will return it. But of course there are exceptions to this rule 😉 So you don’t need this:
echo the_title();
Just use this instead:
the_title();
or the usage example given by @PieterGoosen.
Don’t use extract()
as it’s bad for debugging and deprecated in the core. See for example this answer by @toscho.