Edit
If this is your goal:
I want to use the WordPress gallery to show all pictures of one category in a gallery (on a fixed page), which I do not have to update all the time by inserting the pictures manually.
Then the easiest way to accomplish it is via custom page template.
Create the template
-
Copy your
page.php
template file, and name ittemplate-alpha-gallery.php
-
At the top, add the following:
<?php /** * Template Name: Alpha Gallery */
-
Keep
<?php get_header(); ?>
and<?php get_footer(); ?>
, and whatever HTML markup you need to keep. Delete the existing Loop code. -
Note: the template HTML/loop markup is very Theme-dependent. You’ll need to modify these instructions as appropriate for your current Theme.
-
In place of the Loop code, add the shortcode output from below:
$alpha_attachments = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => 0, 'category_name' => 'alpha', // note: use category SLUG ) ); $alpha_id_array = array(); foreach ( $alpha_attachments->posts as $alpha ) { $alpha_id_array[] = $alpha->ID; } $alpha_ids = implode( ',', $alpha_id_array ); echo do_shortcode( '' );
-
Create a new Static Page, and assign it the “Alpha Gallery” page template
-
Enjoy your gallery
Original Answer
The shortcode doesn’t accept a “category” parameter, however, it does include an
'include'
parameter, that accepts a comma-separated list of attachment IDs:
So, you can use include
to list IDs for all of the attachments that have your specified category.
First, query the correct attachments:
$alpha_attachments = new WP_Query( array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => 0,
'category_name' => 'alpha', // note: use category SLUG
) );
Then, loop through and grab the IDs:
Edit
You need to WordPress loop through the results. Instead of this:
$alpha_id_array = array();
foreach ( $alpha_attachments as $alpha ) {
$alpha_id_array[] = $alpha->ID;
}
…do this:
$alpha_id_array = array();
if ( $alpha_attachments->have_posts() ) : while ( $alpha_attachments->have_posts() ) : $alpha_attachments->the_post();
$alpha_id_array[] = get_the_ID();
endwhile; endif;
// Important!
wp_reset_postdata();
Then, format the string:
$alpha_ids = implode( ',', $alpha_id_array );
Then, pass that string to the shortcode. If you’re using a custom page template, you can do it like so:
echo do_shortcode( '' );
And that should be it.
Edit
When I click on the file, it loads the biggest available size. Can you tell me, where is the link creation or the expression for in which size to open. I created custom sizes vor example “gallerysize” or “blogsize”, but I do not know, how to use them here in this gallery.
The shortcode has a
size
parameter. Just add it to your output; for example, for “medium” images:
echo do_shortcode( '' );