CPT Bootstrap Carousel - Version 1.1

Version Description

  • Added shortcode attributes (code contributed by @joshgerdes)
Download this release

Release Info

Developer tallphil
Plugin Icon 128x128 CPT Bootstrap Carousel
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (2) hide show
  1. cpt-bootstrap-carousel.php +23 -10
  2. readme.txt +28 -3
cpt-bootstrap-carousel.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: CPT Bootstrap Carousel
4
  Plugin URI: http://www.tallphil.co.uk/bootstrap-carousel
5
  Description: A custom post type for choosing images and content which outputs <a href="http://twitter.github.io/bootstrap/javascript.html#carousel" target="_blank">Bootstrap Carousel</a> from a shortcode. Requires Bootstrap javascript and CSS to be loaded separately.
6
- Version: 1.0
7
  Author: Phil Ewels
8
  Author URI: http://phil.ewels.co.uk
9
  License: GPLv2
@@ -61,8 +61,17 @@ add_action( 'after_setup_theme', 'cptbc_addFeaturedImageSupport');
61
  // FRONT END
62
 
63
  // Shortcode
64
- function cptbc_shortcode($atts) {
65
- $atts = (array) $atts;
 
 
 
 
 
 
 
 
 
66
  return cptbc_frontend($atts);
67
  }
68
  add_shortcode('image-carousel', 'cptbc_shortcode');
@@ -88,22 +97,26 @@ function cptbc_frontend($atts){
88
  <div id="cptbc_<?php echo $id; ?>" class="carousel slide">
89
  <ol class="carousel-indicators">
90
  <?php foreach ($images as $key => $image) { ?>
91
- <li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
92
  <?php } ?>
93
  </ol>
94
  <div class="carousel-inner">
95
  <?php foreach ($images as $key => $image) { ?>
96
  <div class="item <?php echo $key == 0 ? 'active' : ''; ?>">
97
  <?php echo $image['image']; ?>
98
- <div class="carousel-caption">
99
- <h4><?php echo $image['title']; ?></h4>
100
- <p><?php echo $image['content']; ?></p>
101
- </div>
 
 
102
  </div>
103
  <?php } ?>
104
  </div>
105
- <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">‹</a>
106
- <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">›</a>
 
 
107
  </div>
108
  <?php }
109
  $output = ob_get_contents();
3
  Plugin Name: CPT Bootstrap Carousel
4
  Plugin URI: http://www.tallphil.co.uk/bootstrap-carousel
5
  Description: A custom post type for choosing images and content which outputs <a href="http://twitter.github.io/bootstrap/javascript.html#carousel" target="_blank">Bootstrap Carousel</a> from a shortcode. Requires Bootstrap javascript and CSS to be loaded separately.
6
+ Version: 1.1
7
  Author: Phil Ewels
8
  Author URI: http://phil.ewels.co.uk
9
  License: GPLv2
61
  // FRONT END
62
 
63
  // Shortcode
64
+ function cptbc_shortcode($atts, $content = null) {
65
+ // Set default shortcode attributes
66
+ $defaults = array(
67
+ 'interval' => '5000',
68
+ 'showcaption' => 'true',
69
+ 'showcontrols' => 'true'
70
+ );
71
+
72
+ // Parse incomming $atts into an array and merge it with $defaults
73
+ $atts = shortcode_atts($defaults, $atts);
74
+
75
  return cptbc_frontend($atts);
76
  }
77
  add_shortcode('image-carousel', 'cptbc_shortcode');
97
  <div id="cptbc_<?php echo $id; ?>" class="carousel slide">
98
  <ol class="carousel-indicators">
99
  <?php foreach ($images as $key => $image) { ?>
100
+ <li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" data-interval="<?php echo $atts['interval']; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
101
  <?php } ?>
102
  </ol>
103
  <div class="carousel-inner">
104
  <?php foreach ($images as $key => $image) { ?>
105
  <div class="item <?php echo $key == 0 ? 'active' : ''; ?>">
106
  <?php echo $image['image']; ?>
107
+ <?php if($atts['showcaption'] === 'true') { ?>
108
+ <div class="carousel-caption">
109
+ <h4><?php echo $image['title']; ?></h4>
110
+ <p><?php echo $image['content']; ?></p>
111
+ </div>
112
+ <?php } ?>
113
  </div>
114
  <?php } ?>
115
  </div>
116
+ <?php if($atts['showcontrols'] === 'true') { ?>
117
+ <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">‹</a>
118
+ <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">›</a>
119
+ <?php } ?>
120
  </div>
121
  <?php }
122
  $output = ob_get_contents();
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === CPT Bootstrap Carousel ===
2
- Contributors: tallphil
3
  Donate Link: http://phil.ewels.co.uk
4
  Tags: carousel, slider, image, bootstrap
5
  Requires at least: 3.0.1
6
  Tested up to: 3.5.1
7
- Stable tag: 1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -21,6 +21,8 @@ The plugin assumes that you're already using Bootstrap, so you need to load the
21
  * [Bootstrap CDN](http://www.bootstrapcdn.com/) _(hotlink CSS and javascript files)_
22
  * [Bootstrap Carousel in action](http://twitter.github.io/bootstrap/examples/carousel.html)
23
 
 
 
24
  I may consider adding an option to load the Bootstrap files in the future if there is demand. Let me know if you'd like it!
25
 
26
  If you'd like to contribute to this plugin, you can find it [hosted on GitHub](https://github.com/tallphil/cpt-bootstrap-carousel).
@@ -33,6 +35,21 @@ If you'd like to contribute to this plugin, you can find it [hosted on GitHub](h
33
  1. Place the `[image-carousel]` shortcode in a Page or Post
34
  1. Create new items in the `Carousel` post type, uploading a Featured Image for each.
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  == Frequently Asked Questions ==
37
 
38
  = Nothing is showing up at all =
@@ -51,5 +68,13 @@ If you'd like to contribute to this plugin, you can find it [hosted on GitHub](h
51
 
52
  == Changelog ==
53
 
 
 
 
54
  = 1.0 =
55
- * Initial release
 
 
 
 
 
1
  === CPT Bootstrap Carousel ===
2
+ Contributors: tallphil, joshgerdes
3
  Donate Link: http://phil.ewels.co.uk
4
  Tags: carousel, slider, image, bootstrap
5
  Requires at least: 3.0.1
6
  Tested up to: 3.5.1
7
+ Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
21
  * [Bootstrap CDN](http://www.bootstrapcdn.com/) _(hotlink CSS and javascript files)_
22
  * [Bootstrap Carousel in action](http://twitter.github.io/bootstrap/examples/carousel.html)
23
 
24
+ The carousel can be tweaked using shortcode attributes, eg: `[image-carousel interval="8000" showcaption="false" showcontrols="false"]`
25
+
26
  I may consider adding an option to load the Bootstrap files in the future if there is demand. Let me know if you'd like it!
27
 
28
  If you'd like to contribute to this plugin, you can find it [hosted on GitHub](https://github.com/tallphil/cpt-bootstrap-carousel).
35
  1. Place the `[image-carousel]` shortcode in a Page or Post
36
  1. Create new items in the `Carousel` post type, uploading a Featured Image for each.
37
 
38
+ = Shortcode Options =
39
+ You can specify how long the carousel pauses for, and whether to display captions and the controls using optional
40
+ shortcode attributes:
41
+
42
+ 1. `interval` _(default 5000)_
43
+ * Length of time for the caption to pause on each image. Time in milliseconds.
44
+ 1. `showcaption` _(default true)_
45
+ * Whether to display the text caption on each image or not. `true` or `false`.
46
+ 1. `showcontrols` _(default true)_
47
+ * Whether to display the control arrows or not. `true` or `false`.
48
+
49
+ For example, to display the carousel with no captions, no controls and pausing for eight seconds, use the following:
50
+ `[image-carousel interval="8000" showcaption="false" showcontrols="false"]`
51
+
52
+
53
  == Frequently Asked Questions ==
54
 
55
  = Nothing is showing up at all =
68
 
69
  == Changelog ==
70
 
71
+ = 1.1 =
72
+ * Added shortcode attributes (code contributed by @joshgerdes)
73
+
74
  = 1.0 =
75
+ * Initial release
76
+
77
+ == Upgrade Notice ==
78
+
79
+ = 1.1 =
80
+ * Added shortcode attribute functionality for tweaking of carousel options.