With this jQuery plugin you can easily slice the WordPress captions into smaller other captions.
Many parameters are available.
Look at the demo page to see it in action.
Why you should be using WPcaptionSlice
- Supports lots of lightboxes and you can manipulate the link and image attributes, like title and alt, and copy one to another.
- Lightweight: less than 5ko of javascript.
- Use the CSS of your WordPress theme, and just add a few CSS if you want it.
- Completely unobtrusive, options are set in the JS and require no changes to existing HTML.
- Written in jQuery plugin format and can be chained with other jQuery commands.
- Generates W3C valid XHTML.
Tested with Firefox 3.6+, Chrome 8+, Safari 5+, Opera 10+, IE6, IE7.
Instructions
- Put WPcaptionSlice folder in ‘/wp-content/themes/your-theme/js/‘.
- Load WPcaptionSlice CSS in
<head>
if you want, after your theme style.<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/js/WPcaptionSlice/WPcaptionSlice.css"/>
- The script needs to use a blank.png. You have to indicate your template directory to the script like this:
<script type="text/javascript">var templdir="<?php bloginfo('template_directory'); ?>";</script>
- Finally, load the script (after jQuery, and before your lightbox script if you have one).
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/WPcaptionSlice/jquery.WPcaptionSlice.js"></script>
The selector must be the image. Remember, the default WordPress caption HTML looks like this:
123456
<div id="attachment_278" class="wp-caption alignnone" style="width: 570px">
<a href="image.jpg">
<img src="image-560x374.jpg" alt="image alt" title="image title" width="560" height="374" class="size-large wp-image-278" />
</a>
<p class="wp-caption-text">Caption text</p>
</div>
The WPcaptionSlice method takes a key/value object.
Format:
$('selector').WPcaptionSlice({key:value, key:value, key:value});
Example:
$('img').WPcaptionSlice();
Example:
$('.size-large').WPcaptionSlice({width:168, height:168, captionPos:4});
Example:
$('.wp-image-279').WPcaptionSlice({width:120, height:120, cols:4, lines:3, whiteSpace:false, linkToImg:false});
See the demonstration page for more examples.
Parameters and default values:
Key | Default | Type | Description |
---|---|---|---|
width | 150 | Number | with for the images (px) |
height | 150 | Number | Height for the images (px) |
cols | 3 | Number | Number of columns |
lines | 2 | Number | Number of lines |
xmin | 5 | Number | Minimum background-position (horizontal) for images (%): in the new captions, the plugin uses the original image for background |
xmax | 95 | Number | Maximum background-position (horizontal) for images (%) |
ymin | 0 | Number | Minimum background-position (vertical) for images (%) |
ymax | 100 | Number | Maximum background-position (vertical) for images (%) |
captionPos | 0 | Number | Caption text position.
|
whiteSpace | true | Boolean or String |
White space under the images.
|
galleryClass | » | String | Additional class for the gallery |
shuffle | false | Boolean or String |
Shuffle mode.
|
imgAlt | true | Boolean | The original image alt attribute is used or is empty |
imgTitle | true | Boolean | The original image title attribute is used or not |
linkToImg | true | Boolean | Links configuration.
|
linkTitle | false | Boolean | The original link title attribute is used or not |
linkRel | false | Boolean or String |
Use link rel attribute or not.
|
imgAltToLinkTitle | false | Boolean | Take the original image alt and put it into links title |
imgTitleToLinkTitle | false | Boolean | Take the original image title and put it into links title |
boxDeltaWidth | 10 | Number | The div.wp-caption width minus the image width (px). In the default WordPress template, this value is 10. |
boxTag | ‘div’ | String | The HTML tag for each image wrapper. |
textTag | ‘p’ | String | The HTML tag for each caption text. |
Commentaires
Commentaire de lashonwp.
Bonjour Gregory
Bravo pour ce tutoriel fort utile, de bonnes idées sympathiques, cher collègue :) . Et bravo pour ce site et blog très agréable à parcourir. Hop dans mes favoris. Bonne journée.
Commentaire de Greg.
Ho, une visite de lashonwp en personne, celui dont le parallax m’a tant fait tripper! :D
Merci pour ta visite et les compliments :) Bonne journée à toi aussi.