Forums Forums Search & Filter Pro How to make the results show an icon

Tagged: ,

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #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
    #37150

    Hey Jeff

    What post type are you searching, or are you searching WP Media/attachments?

    Thanks

    Anonymous
    #37217

    I would like it to show my PDFs from my media library.

    Thanks

    Ross Moderator
    #37229

    Ok 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:

    http://wordpress.stackexchange.com/questions/20081/how-to-get-attachment-file-name-not-attachment-url

    Thanks

    Anonymous
    #37232

    I am using a short code as my display method.

    Thanks

    Anonymous
    #37255

    Where do I put this function?

    <?php get_post_mime_type( $ID ) ?>

    Ross Moderator
    #37622
    This reply has been marked as private.
    Ross Moderator
    #37951

    Hi 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

Viewing 9 posts - 1 through 9 (of 9 total)