WordPress.org

Ready to get started?Download WordPress

Forums

Enhanced Media Library
[resolved] Exporting Set of Images to Frontend (10 posts)

  1. mark.ferguson@thinkzest.com
    Member
    Posted 8 months ago #

    Hello,

    Is there a way in which a set of images that are in a category can be shown on the front end of the site for example, if I had five images in a sub category called 'Banner Images', could I put all five images viewable from the category into a page?

    Many Thanks

    Mark Ferguson

    http://wordpress.org/plugins/enhanced-media-library/

  2. webbistro
    Member
    Plugin Author

    Posted 8 months ago #

    Hello Mark,

    Yes, you can, using same WP query as for any post type belonging to some taxonomy. Use code like this:

    <?php
    $args = array(
    	'post_type' => 'attachment',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'your_taxonomy_slug_here',
    			'field' => 'id',
    			'terms' => 11 // your term ID here
    		)
    	)
    );
    $the_query = new WP_Query( $args );
    
    while ( $the_query->have_posts() )
    {
    	$the_query->the_post();
    	echo wp_get_attachment_image( get_the_ID(), 'thumbnail');
    }
    wp_reset_query();
    ?>

    (http://codex.wordpress.org/Class_Reference/WP_Query)

    You can see your taxonomy slug and term id (id of the 'Banner Images' category) if you open 'Banner Images' for editing. In the URL you will see something like:

    /wp-admin/edit-tags.php?action=edit&taxonomy=document&tag_ID=11&post_type=attachment

    Here, 'document' is taxonomy slug and 11 is term id. If you use "Media Categories' that Enhanced Media Library created by default, then your taxonomy slug is 'media_category'.

    Hope, this will help you.

    Nadia

  3. webbistro
    Member
    Plugin Author

    Posted 8 months ago #

    Also, maybe I misunderstood you. If you need to just add images from some category to some specific page, you can do it via admin. Just click "Add Media" button, filter images by category (http://s.wordpress.org/plugins/enhanced-media-library/screenshot-7.png?r=801136), and insert them into page or make a gallery out of them.

  4. mark.ferguson@thinkzest.com
    Member
    Posted 8 months ago #

    Basically, I need a way in which I have a website which has a top banner at the moment which is made of one image ( you can see here: http://www.uk.arteliagroup.com/sector-expertise/education/).

    These need to get split into five separate images on each page rather than the one image banner and there will be around 10 different variations of these images (10 sets of 5 images). The way in which I though this could be done is by creating the media categories for the different sections I need and then using the Advanced Custom Fields plugin (http://www.advancedcustomfields.com/) create a radio button list which will sit on each page and ask which media category to display. The template would then run an if statement upon this information to select which media categories images to display.

    I hope this makes sense however if you can think of any other way I could do this, it would be greatly appreciated.

    Thanks

    Mark

  5. webbistro
    Member
    Plugin Author

    Posted 8 months ago #

    Got it. Personally, I used other scheme for my clients in this case. I made repeater field with ACF, and each subfield was an image field. So, site admin had to upload/choose images for every page and then show them using code from these examples http://www.advancedcustomfields.com/resources/field-types/repeater/

    But I also like your approach. In this case you have to use code like this:

    <?php
    $term_id = get_field('ACF_TAXONOMY_FIELD_NAME');
    $term_id = $term_id[0];
    
    $args = array(
    	'post_type' => 'attachment',
    	'post_status' => 'inherit',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'YOUR_TAXONOMY_NAME',
    			'field' => 'id',
    			'terms' => $term_id
    		)
    	)
    );
    $the_query = new WP_Query( $args );
    
    while ( $the_query->have_posts() )
    {
    	$the_query->the_post();
    	echo wp_get_attachment_image( get_the_ID(), 'thumbnail');
    }
    wp_reset_query();
    ?>

    Nadia

  6. mark.ferguson@thinkzest.com
    Member
    Posted 8 months ago #

    Thanks very much for coming back to me Nadia. The only problem with that way is that there will be the need for a generic banner (set of 5 images) which will go over 90% of the pages on the site. The problem is if they want to change one of these images, it would need to be done in one place rather than having to go into every page and amend the relevant image.

    Thanks

    Mark

  7. webbistro
    Member
    Plugin Author

    Posted 8 months ago #

    Hello Mark,

    If they change the image(s) and assign it(them) to the same Media Category, the code above will still be working. They just have to make sure that there are only 5 images belong to that Media Category.

    I know that this can be a real challenge for a client, so I still prefer ACF solution in this case. To have ONE set for all the pages, you can use Option Page of ACF. You may call this field group "Generic Banner" or something like and put it to the ACF Option Page, so your client will have to change images in one place, also ACF allows you to set items' limit - no more than 5 images in your case.

    As for EML, I am working right now on some improvements for this plugin. Taxonomy based gallery is one of them. Please stay tuned :)

    And thank you for your feedback!

    Nadia

  8. webbistro
    Member
    Plugin Author

    Posted 8 months ago #

    Hmmm... I think I worked too much today. You can add to the code above

    'posts_per_page' => 5,

    to solve the issue with number of images for your client.

    Full code is:

    <?php
    $term_id = get_field('ACF_TAXONOMY_FIELD_NAME');
    $term_id = $term_id[0];
    
    $args = array(
    	'post_type' => 'attachment',
    	'post_status' => 'inherit',
    	'posts_per_page' => 5,
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'YOUR_TAXONOMY_NAME',
    			'field' => 'id',
    			'terms' => $term_id
    		)
    	)
    );
    $the_query = new WP_Query( $args );
    
    while ( $the_query->have_posts() )
    {
    	$the_query->the_post();
    	echo wp_get_attachment_image( get_the_ID(), 'thumbnail');
    }
    wp_reset_query();
    ?>

    So, the code will always show 5 images belonging to some particular taxonomy term which your client has to choose via admin. But (!) if you need it to work from one place for all the pages, you have to use ACF Options Page anyway.

    I like both solutions.

    Nadia

  9. webbistro
    Member
    Plugin Author

    Posted 8 months ago #

    Hello Mark,

    For now I am marking this topic as resolved. Please feel free to ask additional questions should you have them.

    Nadia

  10. mtissington
    Member
    Posted 5 months ago #

    ANy news about the gallery feature you mentioned?

Reply

You must log in to post.

About this Plugin

About this Topic