Forums › Forums › Search & Filter Pro › How to make the results show an icon
- This topic has 8 replies, 2 voices, and was last updated 8 years, 8 months ago by Ross.
-
Anonymous(Private) February 16, 2016 at 7:29 pm #37096
Hi, is there a way to show an icon of either a PDF or a Word Doc in the search results so the user knows what type of media file is showing up in their search results? Right now in my search results it has no image if it is a media file such as a PDF.
Thanks
Ross Moderator(Private) February 16, 2016 at 11:47 pm #37150Hey Jeff
What post type are you searching, or are you searching WP Media/attachments?
Thanks
Ross Moderator(Private) February 17, 2016 at 4:35 pm #37229Ok so first you would need to customise your results template, are you familiar with this? I can direct you to the correct docs if needed, just tell me which display method you are using? (under the display results tab)
Then you would need to customise this template and I guess use this function to get mime type of the attachment:
https://codex.wordpress.org/Function_Reference/get_post_mime_type
This will get the mime type, and I guess you would display different icons depending on the value of this?
Otherwise you could do a split on the filename and get the file extension I guess and display an icon accordingly:
Thanks
Ross Moderator(Private) February 17, 2016 at 5:24 pm #37233Ross Moderator(Private) February 22, 2016 at 11:57 am #37622This reply has been marked as private.Ross Moderator(Private) February 25, 2016 at 4:38 pm #37951Hi Jeff
I did a quick test as I hadn’t personally used that WP function before.
If you are using the shortcode method for displaying results, then edit your results.php template and on line 52, after the
$query->the_post()
add it there.. so the start of your while loop should look like:<?php while ($query->have_posts()) { $query->the_post(); ?> <?php echo get_post_mime_type(get_the_ID()); ?>
Notice I also added
get_the_ID()
which is sometimes not necessary but a good way to it.Now you can access what file type they are 🙂
Thanks
-
AuthorPosts