Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author webbistro

    (@webbistro)

    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

    Plugin Author webbistro

    (@webbistro)

    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.

    Thread Starter mark.ferguson@thinkzest.com

    (@markfergusonthinkzestcom)

    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

    Plugin Author webbistro

    (@webbistro)

    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

    Thread Starter mark.ferguson@thinkzest.com

    (@markfergusonthinkzestcom)

    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

    Plugin Author webbistro

    (@webbistro)

    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

    Plugin Author webbistro

    (@webbistro)

    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

    Plugin Author webbistro

    (@webbistro)

    Hello Mark,

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

    Nadia

    ANy news about the gallery feature you mentioned?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Exporting Set of Images to Frontend’ is closed to new replies.