how to get the partial filename of a post's featured image? or remove extension?
-
good evening,
i am working on a way to display a small image as an icon for each post. this would normally be handled using a post’s “featured image”, but i am using the featured image as the background for the post, and i want the icon to be a different picture.
my best idea is to simply upload a second picture, with the same name as the featured image but with an additional “_icon” appended to the name. for example “japan.jpg” and “japan_icon.jpg” would be the featured image and the icon.
is there a way to fetch the name of the featured image, without including the file extension? or a way to delete the last three characters of the returned feature image URL?
here’s my loop for setting the featured image as the background :
<?php $args1=array( 'showposts'=>1, 'post_type' => 'page' ); $my_query = new WP_Query($args1); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php $imgID = get_post_thumbnail_id($post->ID); $featuredImage = wp_get_attachment_image_src($imgID, 'full'); $imgURL = $featuredImage[0] ;?> <div class="first" style="background-image: url(<?php echo $imgURL ?>);"> </div> <?php endwhile;} ?>
it would be easy to append “_icon.jpg” to the returned value of $imgURL, and give me my matched icon.
any suggestions would be appreciated ??
- The topic ‘how to get the partial filename of a post's featured image? or remove extension?’ is closed to new replies.