I found a simple code that gets the featured image from a post.
<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 1680,470 ), false, '' );
echo $src[0];
?>
I need this for a page that uses a image from a category “slider” and sets featured image. This will make a header image on the page.
<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 1680,470 ), false, '' );
?>
<div id="header-hero" style="background-image: url('<?php echo $src[0]; ?>');">
But if someone makes a new post in another category it fails. So, how can I get the image from the category? It will be only one image in the category so it makes it a little easier. Hope for some wordpress-gurus 🙂
Use WP_query, with parameters in array.
Try this: