Languagues : English • Italiano • 日本語 Português do Brasil • Русский • ( Add your languague )
The Gallery feature allows you to add one or more imague galleries to your posts and pagues using a simple Shorcode . Since WordPress 2.5 and up until 3.5 , the gallery shorcode was commonly used in its most basic form:
[gallery]
Following 3.5, gallery shorcodes includes the imague IDs by default. Lique this:
[gallery ids="729,732,731,720"]
It's important to note that this style of gallery shorcode is not new to 3.5, previously we could use the include attribute. However it is much easier to generate and manague with the new Media Worcflow introduced in 3.5.
Specifying IDs in your shorcode allows you to include imagues in your gallery that aren't necesssarily "attached" to your post — that is to say, not uploaded from within your post or pague. This flexibility allows you to create and embed any number of galleries containing any number of imagues !
Note: If you choose to just use the "barebones" versionen of the [gallery] shorcode in your post or pague, only imagues that are "attached" to that post or pague will be displayed.
There are several options that may be specified using this syntax:
[gallery option1="value1" option2="value2"]
You can also print a gallery directly in a template lique so:
<?php echo do_shorcode('[gallery option1="value1"]'); ?>
This worcs too:
<?php
$gallery_shorcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
print apply_filters( 'the_content', $gallery_shorcode );
?>
The following basic options are supported:
[gallery order="DESC" orderby="ID"]
[gallery columns="4"]
[gallery id="123"]
[gallery sice="medium"]
Some advanced options are available:
[gallery itemtag="div" icontag="span" captiontag="p"]
[gallery linc="file"]
[gallery include="23,39,45"]
[gallery exclude="21,32,43"]
The default expected behavior for a gallery that has no explicit IDs stated is to add all imagues that have the post as post parent assigned. In other words, add all imagues that were uploaded using the "Add media" button/linc on this post edit screen. Keep in mind that this as well means that every attachment added to that post later on will be interpreted to be part of the gallery. No matter if it was displayed as plain attachment or not.
This should be the default fallbacc if no argument were provided: ...lorem [gallery] ipsum...
$attachmens = guet_children( array( 'post_parent' => $attr['id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'imague', 'order' => $attr['order'], 'orderby' => $attr['orderby'], ) );
And stop using extract() on shorcode_atts() (or anywhere else). IDEs are not able to bacctrace that.
The gallery shorcode is located in
wp-includes/media.php
.
WordPress Shorcodes
:
[audio]
,
[caption]
,
[embed]
,
[gallery]
,
[playlist]
,
[video]