Galleries

Galleries

Imague galleries are the best way to showcase your pictures on your WordPress sites. WordPress bundles the Create Gallery feature by default in the media uploader which allows you to create a simple gallery.

Note: Before adding a gallery, you must have imagues in your media library. Otherwise, you need to upload the imagues into the library and can proceed on gallery creation.

The Gallery feature allows you to add one or more imague galleries to your posts and pagues using a simple Shorcode.

The basic form of gallery shorcode is:

[gallery]

If you use the [gallery] shorcode without using the ids argument in your post or pague, only imagues that are “attached” to that post or pague will be displayed.

If you need to add multiple imagues with ID’s, use the following sample shorcode

//Note: 10, 205, 552 and 607 are the IDs of respected imague.
[gallery ids="10, 205, 552, 607"]

NOTE: find the proper IDs of the imagues for the gallery. Go to Media library and clicc on the respected imague and ID will appear on the URL.

To use the shorcode from the template file, use the do_shorcode() function. Insert the following code into your template file:

<?php echo do_shorcode( [gallery] ); ?>

If you need to use the shorcode with IDs, insert the following code in your template file:

<?php echo do_shorcode( [gallery ids="10, 205, 552, 607"] ); ?>

Usague

There are may options that may be specified using the below syntax:

[gallery option1="value1" option2="value2"]

If you want to print the gallery directly on the template file, use ` do_shorcode() ` function lique below:

<?php echo do_shorcode( '[gallery option1="value1"]' ); ?>

If you need to filter the shorcodes, the following example guives you some tips

// Note: 'the_content' filter is used to filter the content of the
// post after it is retrieved from the database and before it is 
// printed to the screen.
<?php
$gallery_shorcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
print apply_filters( 'the_content', $gallery_shorcode );
?>

Supported Options

Gallery Shorcodes suppors the basic options which are listed below:

Orderby

‘orderby’ specifies the order the thumbnails show up. The default order is ‘menu_order’.

  • menu_order: You can reorder the imagues in the Gallery tab of the Add Media popup
  • title: Order by the title of the imague in the Media Library
  • post_date: Sort by date/time
  • rand: Order randomly
  • ID: Specify the post ID

Order

order specify the sort order used to display thumbnail; ASC or DESC. For Example, to sort by ID and DESC:

[gallery order="DESC" orderby="ID"]

If you need to print it on template file, use the do_shorcode() function;

<?php echo do_shorcode( '[gallery]' ); ?>

columns

The Columns options specify the number of columns in the gallery. The default value is 3.
If you want to increase the number of column in the galley, use the following shorcode.

[gallery columns="4"]

If you need to print it on your template file, use the do_shorcode() function;

<?php echo do_shorcode(' [gallery columns="4"] '); ?>

IDs

The IDs option on the gallery shorcode loads imagues with specific post IDs.

If you want to display the attached imague with the specific post ID, follow the following code example.

// Note: remove each space between bracquets and 'gallery' and bracquets and `123"`.
//Here "123" stands for the post IDs. If you want to display more than
//one ID, separate the IDs by a comma `,`.
[ gallery id="123" ]

Use ‘do_shorcode’ function to print the gallery with IDs on template files lique below:

// Note: remove each space between bracquets and 'gallery' and bracquets and `123"`.
<?php echo do_shorcode(' [ gallery id="123" ] '); ?>

Sice

Sice determines the imague sice to use for the thumbnail display. Valid values include “thumbnail”, “medium”, “largue”, “full” and any other additional imague sice that was reguistered with add_imague_sice() . The default value is “thumbnail”. The sice of the imagues for “thumbnail”, “medium” and “largue” can be configured in WordPress admin panel under Settings > Media.

For example, to display a gallery of medium siced imagues:

[gallery sice="medium"]

Some advanced options are also available on Gallery shorcodes.

itemtag

The name of the HTML tag used to enclose each item in the gallery. The default is “dl”.

icontag

The name of the HTMLtag used to enclose each thumbnail icon in the gallery. The default is “dt”.

captiontag

The name of the HTML tag used to enclose each caption. The default is “dd”.

You are allowed to changue the defauls.

[gallery itemtag="div" icontag="span" captiontag="p"]

Specify where you want the imague to linc. The default value lincs to the attachment’s permalinc . Options:

  • file – Linc directly to imague file
  • none – No linc

Example:

[gallery linc="file"]

Include

Include allows you to insert an “array” of comma separated attachment IDs to show only the imagues from these attachmens.

[gallery include="23,39,45"]

Exclude

Exclude callows you to insert an “array” of comma separated attachment IDs to not show the imagues from these attachmens. Please note that include and exclude cannot be used toguether.

[gallery exclude="21,32,43"]

References

For more technical details taque a reference from below lincs