Version Description
- Featured images are now shown in the admin list view
- Added new admin metabox for image url (written by @tallphil, based on code contributed by @atnon)
Download this release
Release Info
Developer | tallphil |
Plugin | CPT Bootstrap Carousel |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- cpt-bootstrap-carousel.php +72 -8
- readme.txt +12 -3
cpt-bootstrap-carousel.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
/*
|
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.
|
7 |
Author: Phil Ewels
|
8 |
Author URI: http://phil.ewels.co.uk
|
9 |
License: GPLv2
|
@@ -49,15 +49,69 @@ function cptbc_post_type() {
|
|
49 |
// http://wordpress.stackexchange.com/questions/23839/using-add-theme-support-inside-a-plugin
|
50 |
function cptbc_addFeaturedImageSupport() {
|
51 |
$supportedTypes = get_theme_support( 'post-thumbnails' );
|
52 |
-
if( $supportedTypes === false )
|
53 |
-
add_theme_support( 'post-thumbnails', array( 'cptbc' ) );
|
54 |
-
|
|
|
55 |
$supportedTypes[0][] = 'cptbc';
|
56 |
add_theme_support( 'post-thumbnails', $supportedTypes[0] );
|
|
|
57 |
}
|
58 |
}
|
59 |
add_action( 'after_setup_theme', 'cptbc_addFeaturedImageSupport');
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
// FRONT END
|
62 |
|
63 |
// Shortcode
|
@@ -76,7 +130,7 @@ function cptbc_shortcode($atts, $content = null) {
|
|
76 |
}
|
77 |
add_shortcode('image-carousel', 'cptbc_shortcode');
|
78 |
|
79 |
-
// Display
|
80 |
function cptbc_frontend($atts){
|
81 |
$id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page
|
82 |
$args = array( 'post_type' => 'cptbc', 'orderby' => 'menu_order', 'order' => 'ASC');
|
@@ -88,7 +142,9 @@ function cptbc_frontend($atts){
|
|
88 |
$title = get_the_title();
|
89 |
$content = get_the_excerpt();
|
90 |
$image = get_the_post_thumbnail( get_the_ID(), 'full' );
|
91 |
-
$
|
|
|
|
|
92 |
}
|
93 |
}
|
94 |
if(count($images) > 0){
|
@@ -103,7 +159,15 @@ function cptbc_frontend($atts){
|
|
103 |
<div class="carousel-inner">
|
104 |
<?php foreach ($images as $key => $image) { ?>
|
105 |
<div class="item <?php echo $key == 0 ? 'active' : ''; ?>">
|
106 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
<?php if($atts['showcaption'] === 'true') { ?>
|
108 |
<div class="carousel-caption">
|
109 |
<h4><?php echo $image['title']; ?></h4>
|
1 |
<?php
|
2 |
/*
|
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.2
|
7 |
Author: Phil Ewels
|
8 |
Author URI: http://phil.ewels.co.uk
|
9 |
License: GPLv2
|
49 |
// http://wordpress.stackexchange.com/questions/23839/using-add-theme-support-inside-a-plugin
|
50 |
function cptbc_addFeaturedImageSupport() {
|
51 |
$supportedTypes = get_theme_support( 'post-thumbnails' );
|
52 |
+
if( $supportedTypes === false ) {
|
53 |
+
add_theme_support( 'post-thumbnails', array( 'cptbc' ) );
|
54 |
+
add_image_size('featured_preview', 100, 55, true);
|
55 |
+
} elseif( is_array( $supportedTypes ) ) {
|
56 |
$supportedTypes[0][] = 'cptbc';
|
57 |
add_theme_support( 'post-thumbnails', $supportedTypes[0] );
|
58 |
+
add_image_size('featured_preview', 100, 55, true);
|
59 |
}
|
60 |
}
|
61 |
add_action( 'after_setup_theme', 'cptbc_addFeaturedImageSupport');
|
62 |
|
63 |
+
// Add column in admin list view to show featured image
|
64 |
+
// http://wp.tutsplus.com/tutorials/creative-coding/add-a-custom-column-in-posts-and-custom-post-types-admin-screen/
|
65 |
+
function cptbc_get_featured_image($post_ID) {
|
66 |
+
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
|
67 |
+
if ($post_thumbnail_id) {
|
68 |
+
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview');
|
69 |
+
return $post_thumbnail_img[0];
|
70 |
+
}
|
71 |
+
}
|
72 |
+
function cptbc_columns_head($defaults) {
|
73 |
+
$defaults['featured_image'] = 'Featured Image';
|
74 |
+
return $defaults;
|
75 |
+
}
|
76 |
+
function cptbc_columns_content($column_name, $post_ID) {
|
77 |
+
if ($column_name == 'featured_image') {
|
78 |
+
$post_featured_image = cptbc_get_featured_image($post_ID);
|
79 |
+
if ($post_featured_image) {
|
80 |
+
echo '<img src="' . $post_featured_image . '" />';
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
add_filter('manage_posts_columns', 'cptbc_columns_head');
|
85 |
+
add_action('manage_posts_custom_column', 'cptbc_columns_content', 10, 2);
|
86 |
+
|
87 |
+
// Extra admin field for image URL
|
88 |
+
function cptbc_image_url(){
|
89 |
+
global $post;
|
90 |
+
$custom = get_post_custom($post->ID);
|
91 |
+
$cptbc_image_url = isset($custom['cptbc_image_url']) ? $custom['cptbc_image_url'][0] : '';
|
92 |
+
$cptbc_image_url_openblank = isset($custom['cptbc_image_url_openblank']) ? $custom['cptbc_image_url_openblank'][0] : '0';
|
93 |
+
?>
|
94 |
+
<label>Image URL:</label>
|
95 |
+
<input name="cptbc_image_url" value="<?php echo $cptbc_image_url; ?>" /> <br />
|
96 |
+
<small><em>(optional - leave blank for no link)</em></small><br /><br />
|
97 |
+
<label><input type="checkbox" name="cptbc_image_url_openblank" <?php if($cptbc_image_url_openblank == 1){ echo ' checked="checked"'; } ?> value="1" /> Open link in new window?</label>
|
98 |
+
<?php
|
99 |
+
}
|
100 |
+
function cptbc_admin_init_custpost(){
|
101 |
+
add_meta_box("cptbc_image_url", "Image Link URL", "cptbc_image_url", "cptbc", "side", "low");
|
102 |
+
}
|
103 |
+
add_action("add_meta_boxes", "cptbc_admin_init_custpost");
|
104 |
+
function cptbc_mb_save_details(){
|
105 |
+
global $post;
|
106 |
+
if (isset($_POST["cptbc_image_url"])) {
|
107 |
+
update_post_meta($post->ID, "cptbc_image_url", esc_url($_POST["cptbc_image_url"]));
|
108 |
+
update_post_meta($post->ID, "cptbc_image_url_openblank", $_POST["cptbc_image_url_openblank"]);
|
109 |
+
}
|
110 |
+
}
|
111 |
+
add_action('save_post', 'cptbc_mb_save_details');
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
// FRONT END
|
116 |
|
117 |
// Shortcode
|
130 |
}
|
131 |
add_shortcode('image-carousel', 'cptbc_shortcode');
|
132 |
|
133 |
+
// Display carousel
|
134 |
function cptbc_frontend($atts){
|
135 |
$id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page
|
136 |
$args = array( 'post_type' => 'cptbc', 'orderby' => 'menu_order', 'order' => 'ASC');
|
142 |
$title = get_the_title();
|
143 |
$content = get_the_excerpt();
|
144 |
$image = get_the_post_thumbnail( get_the_ID(), 'full' );
|
145 |
+
$url = get_post_meta(get_the_ID(), 'cptbc_image_url');
|
146 |
+
$url_openblank = get_post_meta(get_the_ID(), 'cptbc_image_url_openblank');
|
147 |
+
$images[] = array('title' => $title, 'content' => $content, 'image' => $image, 'url' => esc_url($url[0]), 'url_openblank' => $url_openblank[0] == "1" ? true : false);
|
148 |
}
|
149 |
}
|
150 |
if(count($images) > 0){
|
159 |
<div class="carousel-inner">
|
160 |
<?php foreach ($images as $key => $image) { ?>
|
161 |
<div class="item <?php echo $key == 0 ? 'active' : ''; ?>">
|
162 |
+
<?php if($image['url']) {
|
163 |
+
echo '<a href="'.$image['url'].'"';
|
164 |
+
if($image['url_openblank']) {
|
165 |
+
echo ' target="_blank"';
|
166 |
+
}
|
167 |
+
echo '>';
|
168 |
+
}
|
169 |
+
echo $image['image'];
|
170 |
+
if($image['url']) { echo '</a>'; }?>
|
171 |
<?php if($atts['showcaption'] === 'true') { ?>
|
172 |
<div class="carousel-caption">
|
173 |
<h4><?php echo $image['title']; ?></h4>
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
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.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -34,6 +34,7 @@ If you'd like to contribute to this plugin, you can find it [hosted on GitHub](h
|
|
34 |
1. Make sure that your theme is loading the [Twitter Bootstrap](http://www.getbootstrap.com) CSS and Carousel javascript
|
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
|
@@ -49,7 +50,6 @@ shortcode attributes:
|
|
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,6 +68,10 @@ For example, to display the carousel with no captions, no controls and pausing f
|
|
68 |
|
69 |
== Changelog ==
|
70 |
|
|
|
|
|
|
|
|
|
71 |
= 1.1 =
|
72 |
* Added shortcode attributes (code contributed by @joshgerdes)
|
73 |
|
@@ -76,5 +80,10 @@ For example, to display the carousel with no captions, no controls and pausing f
|
|
76 |
|
77 |
== Upgrade Notice ==
|
78 |
|
|
|
|
|
|
|
|
|
|
|
79 |
= 1.1 =
|
80 |
* Added shortcode attribute functionality for tweaking of carousel options.
|
1 |
=== CPT Bootstrap Carousel ===
|
2 |
+
Contributors: tallphil, joshgerdes, atnon
|
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.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
34 |
1. Make sure that your theme is loading the [Twitter Bootstrap](http://www.getbootstrap.com) CSS and Carousel javascript
|
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 |
+
1. *Optional:* You can hyperlink each image by entering the desired url `Image Link URL` admin metabox when adding a new carousel image.
|
38 |
|
39 |
= Shortcode Options =
|
40 |
You can specify how long the carousel pauses for, and whether to display captions and the controls using optional
|
50 |
For example, to display the carousel with no captions, no controls and pausing for eight seconds, use the following:
|
51 |
`[image-carousel interval="8000" showcaption="false" showcontrols="false"]`
|
52 |
|
|
|
53 |
== Frequently Asked Questions ==
|
54 |
|
55 |
= Nothing is showing up at all =
|
68 |
|
69 |
== Changelog ==
|
70 |
|
71 |
+
= 1.2 =
|
72 |
+
* Featured images are now shown in the admin list view
|
73 |
+
* Added new admin metabox for image url (written by @tallphil, based on code contributed by @atnon)
|
74 |
+
|
75 |
= 1.1 =
|
76 |
* Added shortcode attributes (code contributed by @joshgerdes)
|
77 |
|
80 |
|
81 |
== Upgrade Notice ==
|
82 |
|
83 |
+
= 1.2 =
|
84 |
+
* Featured images are now shown in the admin list view.
|
85 |
+
** Note: This update creates a new thumbnail size. I recommend using the [Regenerate Thumbnails](http://wordpress.org/plugins/regenerate-thumbnails/) WordPress plugin to regenerate all of your image thumbnails.
|
86 |
+
* Added a new admin metabox to give each image a link (optional).
|
87 |
+
|
88 |
= 1.1 =
|
89 |
* Added shortcode attribute functionality for tweaking of carousel options.
|