adding a link to see all the uploaded file from bbpress

Hi,
I have a bbpress site with a plugin that allows users to upload files into the post. The file then gets stored in the media library. The forum is for a class and I want it to be able so that other students can look at all the uploaded files in the front end of the site. Is there a way to do that? Even a link to another page that would have a list of all the files would be fine. If possible I also dont want this list to have all uploaded files, because then it would include each students avatars.
Thank you so so much!

  • Vinod Dalvi
    • WP Unicorn

    Hi Jonathan,

    I hope you are well today and thank you for your question.

    You can use the following custom code in your child theme template file to display all the files stored in the media library.

    <?php
    
    $args = array(
        'post_type' => 'attachment',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => null, // any parent
        );
    $attachments = get_posts($args);
    if ($attachments) {
        foreach ($attachments as $post) {
            setup_postdata($post);
            the_title();
            the_attachment_link($post->ID, false);
            the_excerpt();
        }
    }
    
    ?>

    You can just use 'post_mime_type' => 'image' or any MIME type in your $args, and WordPress will cleverly match that against all mime types and only fetch the files from media library of that particular MIME type.

    Best Regards,
    Vinod Dalvi

  • Jonathan
    • The Crimson Coder

    thanks.
    Im not using a child theme, but I can just ad this as a plugin and therefore it wont get overridden, correct?
    Also, Im sorry but im only a deisgner (not dev) and your instructions after the block of code i dont totally understand them. Could you give me instructions that I would understand if Im a wordpress designer, knowing html and css, and some very basic php. Thanks!!!!

  • Vinod Dalvi
    • WP Unicorn

    Hi Jonathan,

    Thank you for your reply.

    Yes you can use the shared code by adding it in the new plugin but keep in mind that you can't override theme templates in plugin so you have to use WordPress hook to display the output of this code on the page where you want to display it.

    Could you please tell me what you are not understanding so that i can describe it more in detail?

    If you are not a programmer then you can also consider hiring a developer from https://premium.wpmudev.org/wpmu-custom-development/ to develop it for you.

    Regards,
    Vinod Dalvi

  • Jonathan
    • The Crimson Coder

    Thanks.
    OK i installed a child theme via a plug called "one click child theme."
    Could you please tell me what directory I need to create to put the code above in?
    Then I should add 'post_mime_type' => 'image'
    to the code above?
    Is that correct?
    Also, how/where do I see this on the front side of the site?

  • Ash
    • WordPress Hacker

    Hello @Jonathan

    I hope you are well today.

    Please undo whatever you did so far. Then install the attached plugin and activate. Then use the following shortcode in any post or page:

    [show_media]

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello @Jonathan

    How are you allowing user to upload media? Using any plugin or custom code? Though, I don't think it would be possible but I want to give a try.

    also this plugin ads the page title before each file, how can I switch that to display to file name?

    Please delete the previous plugin and install the attached one.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Jonathan
    • The Crimson Coder

    Thanks a lot.
    I'm using a plugin: https://wordpress.org/plugins/gd-bbpress-attachments/
    From the first response on the thread my impression was there was a way to show only a certain MIME type. That would be great as I can write on the forum that all uploaded documents need to be a pdf as my main concern is that this "upload page" will also show all users' favicons which I dont want. I may have misunderstood what Vinod said above. THanks so so much

  • Ash
    • WordPress Hacker

    Hello @Jonathan

    I hope you are well today.

    I am sorry for the delay.

    From the first response on the thread my impression was there was a way to show only a certain MIME type.

    Vinod meant about uploaded file type, like you can fetch all images or all mp3 files etc. But there is no way to fetch only the files that is uploaded via bbpress.

    I never used gd-bbpress-attachments plugin. Would you please ask the plugin developer if they save any meta data to those files that are uploaded via bbpress, then we can get those files using that meta value. If they don't store any meta value, then there is no way I am afraid.

    Please let me know what you hear back from the developer.

    Cheers
    Ash

  • Jonathan
    • The Crimson Coder

    I will ask the developer.
    In case there is no meta data attached, I so not need to use this plugin. So if you knew of another way I could give users the option to upload files, that would be fine. I actually wanted to use the wpmu forums plugin, but when trying to translate it, it got all messed up and I saw that on your support it happened to others and bbpress worked great right out of the box. So if there was another plugin or custom code I could add that would make this work, that would help me a lot. Do you know of anything/anyway to do that?
    In the meantime, I will try to contact the plugin dev.
    Thanks for all your help.
    Jonathan

  • Jonathan
    • The Crimson Coder

    The developer is not offering support for the free plugin. Is there a way to look at the code to see if any meta data is attached?
    Also, if using mime, we can just have that page show only pdfs, that would suffice, as the main thing I want is that the page will not also show the favicon files. Would we still need meta data for that?

  • Ash
    • WordPress Hacker

    Hello @Jonathan

    if using mime, we can just have that page show only pdfs, that would suffice,

    I think this is possible. Please try the attached plugin.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.