I found what I needed:
$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;
$images = get_posts( array('post_type' => 'attachment', 'category__in' => $cat_id));
if ( !empty($images) ) {
foreach ( $images as $image ) {
$image_url = $image->guid;
}
} else{
$image_url="";
}
First I got the category, and current category ID I’m in. Then in $images
I got the attachment that’s attached to this category. Then I just listed them (I used print_r
to see all the array values fro $images) and found the url (I need the url of the image to set the background image in the breadcrumbs). You can get the image directly by using wp_get_attachment_image($image->ID)
, but I need the url so I’m using this.
Oh and I’m avoiding the plugin usage, since I’m building a theme, and I’d like everything to be available from the theme itself.
Hope this helps someone 🙂