WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "User:DrewAPicture"

m
(Gallery shortcode tryout)
Line 17: Line 17:
   
 
Please see my [http://profiles.wordpress.org/users/DrewAPicture WordPress profile].
 
Please see my [http://profiles.wordpress.org/users/DrewAPicture WordPress profile].
  +
  +
  +
{{mbox|text=Gallery Shortcode stuff}}
  +
  +
In WordPress, the Gallery feature allows you to one or more image galleries to your posts and pages.
  +
  +
Up until WordPress [[Version_3.5|3.5]], the gallery shortcode was most often used in this form:
  +
  +
<tt>[gallery]</tt>
  +
  +
Following 3.5, you can still use parameters like before -- you can still use <tt>[gallery]</tt> just like before -- but it's more likely you'll see gallery shortcodes similar to this format:
  +
  +
<tt>[gallery ids="729,732,731,720"]</tt>
  +
  +
This new-ish format (which was previously possible), allows you to include images in your gallery that aren't necessarily "attached" to your post -- that is to say, not uploaded from within your post or page. This flexibility allows you to create and embed any number of galleries containing any number of images!
  +
  +
'''Note:''' If you choose to just use the <tt>[gallery]</tt> shortcode in your post or page, the shortcode will only include images that are "attached" to that post or page. This is not new behavior to 3.5.
  +
  +
  +
== Examples ==
  +
  +
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 like so:
  +
  +
<?php echo do_shortcode('[gallery option1="value1"]'); ?>
  +
  +
This works too:
  +
  +
<?php
  +
$gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
  +
print apply_filters( 'the_content', $gallery_shortcode );
  +
?>
  +
  +
== Parameters ==
  +
  +
The following basic options are supported:
  +
  +
; orderby : specify how to sort the display thumbnails. The default is "menu_order". Options:
  +
* menu_order - you can reorder the images in the Gallery tab of the Add Media pop-up
  +
* title - order by the title of the image in Media
  +
* post_date - sort by date/time
  +
* rand - order randomly
  +
* ID
  +
  +
; order : specify the sort order used to display thumbnails. ASC or DESC. For example, to sort by ID, DESC:
  +
  +
[gallery order="DESC" orderby="ID"]
  +
  +
; columns : specify the number of columns. The gallery will include a break tag at the end of each row, and calculate the column width as appropriate. The default value is 3. If columns is set to 0, no row breaks will be included. For example, to display a 4 column gallery:
  +
  +
[gallery columns="4"]
  +
  +
; id : specify the post ID. The gallery will display images which are attached to that post. The default behavior if no ID is specified is to display images attached to the current post. For example, to display images attached to post 123:
  +
  +
[gallery id="123"]
  +
  +
; size : specify the image size to use for the thumbnail display. Valid values include "thumbnail", "medium", "large", "full" and any other additional image size that was registered with [[Function Reference/add_image_size | add_image_size()]]. The default value is "thumbnail". The size of the images for "thumbnail", "medium" and "large" can be configured in WordPress admin panel under Settings > Media. For example, to display a gallery of medium sized images:
  +
  +
[gallery size="medium"]
  +
  +
Some advanced options are available:
  +
  +
; itemtag : the name of the XHTML tag used to enclose each item in the gallery. The default is "dl".
  +
  +
; icontag : the name of the XHTML tag used to enclose each thumbnail icon in the gallery. The default is "dt".
  +
  +
; captiontag: the name of the XHTML tag used to enclose each caption. The default is "dd". For example, to change the gallery markup to use div, span and p tags:
  +
  +
[gallery itemtag="div" icontag="span" captiontag="p"]
  +
  +
; link: you can set it to "file" so each image will link to the image file. The default value links to the attachment's permalink.
  +
  +
[gallery link="file"]
  +
  +
; include: comma separated attachment IDs to show only the images from these attachments.
  +
  +
[gallery include="23,39,45"]
  +
  +
; exclude: comma separated attachment IDs excludes the images from these attachments. Please note that '''include''' and '''exclude''' cannot be used together.
  +
  +
[gallery exclude="21,32,43"]
  +
  +
[[Category:Advanced Topics]]
  +
[[Category:WordPress Development]]
  +
[[Category:Shortcodes]]

Revision as of 21:55, 14 December 2012

Drew Jaynes (DrewAPicture)

Recent Edits

http://codex.wordpress.org/index.php?title=Special:Contributions&target=DrewAPicture

About Me

Howdy! Many people know me simply as DrewAPicture but my real name is Drew Jaynes. If you need to get in touch, you can email me at drew [at] drewapicture.com or send me a tweet at @DrewAPicture.

I've been working in and developing with WordPress since 2009. I do freelance WordPress design and development in Denver, Colorado. I also Co-Organize the Denver WordPress Meetup, contribute to core, and volunteer on the support and docs teams.

Since I'm in the Codex usually several times I day, most of my changes have been tweaks to example functions, clarifying and general copy editing as well as coding standards changes in articles throughout the Codex.

I'm interested in branching out into creating entirely new articles and assisting with general Codex cleanup efforts.

Please see my WordPress profile.


[[File:{{{image}}}|40px|alt=Attention|middle]] Gallery Shortcode stuff

In WordPress, the Gallery feature allows you to one or more image galleries to your posts and pages.

Up until WordPress 3.5, the gallery shortcode was most often used in this form:

[gallery]

Following 3.5, you can still use parameters like before -- you can still use [gallery] just like before -- but it's more likely you'll see gallery shortcodes similar to this format:

[gallery ids="729,732,731,720"]

This new-ish format (which was previously possible), allows you to include images in your gallery that aren't necessarily "attached" to your post -- that is to say, not uploaded from within your post or page. This flexibility allows you to create and embed any number of galleries containing any number of images!

Note: If you choose to just use the [gallery] shortcode in your post or page, the shortcode will only include images that are "attached" to that post or page. This is not new behavior to 3.5.


Examples

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 like so:

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

This works too:

 <?php
    $gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
    print apply_filters( 'the_content', $gallery_shortcode );
 ?>

Parameters

The following basic options are supported:

orderby 
specify how to sort the display thumbnails. The default is "menu_order". Options:
  • menu_order - you can reorder the images in the Gallery tab of the Add Media pop-up
  • title - order by the title of the image in Media
  • post_date - sort by date/time
  • rand - order randomly
  • ID
order 
specify the sort order used to display thumbnails. ASC or DESC. For example, to sort by ID, DESC:
 [gallery order="DESC" orderby="ID"]
columns 
specify the number of columns. The gallery will include a break tag at the end of each row, and calculate the column width as appropriate. The default value is 3. If columns is set to 0, no row breaks will be included. For example, to display a 4 column gallery:
[gallery columns="4"]
id 
specify the post ID. The gallery will display images which are attached to that post. The default behavior if no ID is specified is to display images attached to the current post. For example, to display images attached to post 123:
[gallery id="123"]
size 
specify the image size to use for the thumbnail display. Valid values include "thumbnail", "medium", "large", "full" and any other additional image size that was registered with add_image_size(). The default value is "thumbnail". The size of the images for "thumbnail", "medium" and "large" can be configured in WordPress admin panel under Settings > Media. For example, to display a gallery of medium sized images:
[gallery size="medium"]

Some advanced options are available:

itemtag 
the name of the XHTML tag used to enclose each item in the gallery. The default is "dl".
icontag 
the name of the XHTML tag used to enclose each thumbnail icon in the gallery. The default is "dt".
captiontag
the name of the XHTML tag used to enclose each caption. The default is "dd". For example, to change the gallery markup to use div, span and p tags:
[gallery itemtag="div" icontag="span" captiontag="p"]
link
you can set it to "file" so each image will link to the image file. The default value links to the attachment's permalink.
[gallery link="file"] 
include
comma separated attachment IDs to show only the images from these attachments.
[gallery include="23,39,45"] 
exclude
comma separated attachment IDs excludes the images from these attachments. Please note that include and exclude cannot be used together.
[gallery exclude="21,32,43"]