-
Notifications
You must be signed in to change notification settings - Fork 0
/
pegasus-slider.php
284 lines (218 loc) · 9.3 KB
/
pegasus-slider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/*
Plugin Name: Pegasus Slider Plugin
Plugin URI: https://developer.wordpress.org/plugins/the-basics/
Description: This allows you to create sliders on your website with just a shortcode.
Version: 1.0
Author: Jim O'Brien
Author URI: https://visionquestdevelopment.com/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wporg
Domain Path: /languages
*/
/**
* Silence is golden; exit if accessed directly
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function pegasus_slider_menu_item() {
//add_menu_page("Slider", "Slider", "manage_options", "pegasus_slider_plugin_options", "pegasus_slider_plugin_settings_page", null, 99);
//add_submenu_page("pegasus_slider_plugin_options", "Shortcode Usage", "Usage", "manage_options", "pegasus_slider_plugin_shortcode_options", "pegasus_slider_plugin_shortcode_settings_page" );
}
add_action("admin_menu", "pegasus_slider_menu_item");
function pegasus_slider_plugin_settings_page() { ?>
<div class="wrap">
<h1>Slider</h1>
<form method="post" action="options.php">
<?php
settings_fields("section");
do_settings_sections("theme-options");
submit_button();
?>
</form>
</div>
<?php
}
function pegasus_slider_plugin_shortcode_settings_page() { ?>
<div class="wrap pegasus-wrap">
<h1>Shortcode Usage</h1>
<p>Slider Usage: <pre>[slider][slide class="testing"]<?php echo htmlspecialchars('<img class="alignnone size-full wp-image-12" src="http://www.fillmurray.com/960/550" alt="Gold-and-Black-Logo">'); ?>[/slide][slide]<?php echo htmlspecialchars('<img class="alignnone size-full wp-image-12" src="http://www.fillmurray.com/600/350" alt="Gold-and-Black-Logo">'); ?>[/slide][/slider]</pre></p>
<p>Post Slider Usage: <pre>[news_slider the_query="showposts=100&post_type=post"]</pre> </p>
<p>Thumb Slider Usage: <pre>[thumb_slider][thumb_slide title="slide1" number="1"]<?php echo htmlspecialchars('<img src="http://slippry.com/assets/img/image-1.jpg" alt="This is caption 1">'); ?>[/thumb_slide][thumb_slide title="slide2" number="2"]<?php echo htmlspecialchars('<img src="http://slippry.com/assets/img/image-2.jpg" alt="This is caption 2">'); ?>[/thumb_slide][thumb_slide title="slide3" number="3"]<?php echo htmlspecialchars('<img src="http://slippry.com/assets/img/image-3.jpg" alt="This is caption 3">'); ?>[/thumb_slide][thumb_slide title="slide4" number="4"]<?php echo htmlspecialchars('<img src="http://slippry.com/assets/img/image-4.jpg" alt="This is caption 4">'); ?>[/thumb_slide][/thumb_slider]</pre></p>
<p style="color:red;">MAKE SURE YOU DO NOT HAVE ANY RETURNS OR <?php echo htmlspecialchars('<br>'); ?>'s IN YOUR SHORTCODES, OTHERWISE IT WILL NOT WORK CORRECTLY</p>
</div>
<?php
}
function pegasus_slider_plugin_styles() {
wp_register_style( 'slippery-css', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'css/slippery.css', array(), null, 'all' );
wp_register_style( 'slippery-slider-css', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'css/slippery-slider.css', array(), null, 'all' );
}
add_action( 'wp_enqueue_scripts', 'pegasus_slider_plugin_styles' );
/**
* Proper way to enqueue JS
*/
function pegasus_slider_plugin_js() {
wp_register_script( 'slippery-js', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/slippery.js', array( 'jquery' ), null, 'all' );
wp_register_script( 'pegasus-slider-plugin-js', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/plugin.js', array( 'jquery' ), null, 'all' );
} //end function
add_action( 'wp_enqueue_scripts', 'pegasus_slider_plugin_js' );
/*~~~~~~~~~~~~~~~~~~~~
SLIDER / carousel
~~~~~~~~~~~~~~~~~~~~~*/
/**
* Slider Short Code
*/
if ( ! class_exists( 'SliderClass' ) ) {
class SliderClass {
protected $_slider_divs;
public function __construct($slider_divs = '') {
$this->_slider_divs = $slider_divs;
add_shortcode( 'slider', array( $this, 'slider_wrap') );
add_shortcode( 'slide', array( $this,'slider_block') );
}
function slider_wrap ( $args, $content = null ) {
$wrapOutput = '';
$wrapOutput .= '<ul class="slippry-slider-container ">';
$wrapOutput .= do_shortcode($content);
$wrapOutput .= '</ul>';
wp_enqueue_style( 'slippery-css' );
wp_enqueue_style( 'slippery-slider-css' );
wp_enqueue_script( 'slippery-js' );
wp_enqueue_script( 'pegasus-slider-plugin-js' );
return $wrapOutput;
}
function slider_block( $args, $content = null ) {
extract( shortcode_atts( array(
'id' => '',
'title' => '',
'class' => '',
), $args ) );
$slideOutput = '<li class="'. $class .'"><a href="#slide'. $id .'" alt="'. $title .'">'.$content.'</a></li>';
return $slideOutput;
}
}
new SliderClass;
}
/*~~~~~~~~~~~~~~~~~~~~
THUMB SLIDER / carousel
~~~~~~~~~~~~~~~~~~~~~*/
if ( ! class_exists( 'ThumbSliderClass' ) ) {
class ThumbSliderClass {
protected $_slider_divs;
public function __construct($slider_divs = '') {
$this->_slider_divs = $slider_divs;
add_shortcode( 'thumb_slider', array( $this, 'slider_wrap') );
add_shortcode( 'thumb_slide', array( $this,'slider_block') );
}
function slider_wrap ( $args, $content = null ) {
$output = '';
$output .= '<ul id="thumbnails">';
$output .= do_shortcode($content);
$output .= '</ul>';
$output .= '<div class="thumb-box"> <ul class="thumbs">';
$output .= $this->_slider_divs;
$output .= '</ul></div>';
wp_enqueue_style( 'slippery-css' );
wp_enqueue_style( 'slippery-slider-css' );
wp_enqueue_script( 'slippery-js' );
wp_enqueue_script( 'pegasus-slider-plugin-js' );
return $output;
}
function slider_block( $args, $content = null ) {
extract(shortcode_atts(array(
'id' => '',
'title' => '',
'class' => '',
'number' => '',
), $args));
$output = '<li><a href="#'.$title.'" alt="This is caption 2">'.$content.'</a></li>';
$this->_slider_divs.= '<li><a href="#'.$number.'" data-slide="'.$number.'">'.$content.'</a></li>';
return $output;
}
}
new ThumbSliderClass;
}
/*~~~~~~~~~~~~~~~~~~~~
News Slider shortcode
~~~~~~~~~~~~~~~~~~~~~*/
// [news_slider the_query="showposts=100&post_type=page&post_parent=453" bkg_color="#dedede" ]
function news_slider_query_shortcode($atts) {
$a = shortcode_atts( array(
//"bkg_color" => ''
), $atts );
// Defaults
extract(shortcode_atts(array(
"the_query" => '',
), $atts));
// de-funkify query
//$the_query = preg_replace('~�*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $the_query);
//$the_query = preg_replace('~�*([0-9]+);~e', 'chr(\\1)', $the_query);
$the_query = preg_replace_callback('~�*([0-9a-f]+);~', function($matches){
return chr( dechex( $matches[1] ) );
}, $the_query );
$the_query = preg_replace_callback('~�*([0-9]+);~', function($matches){
return chr( $matches[1] );
}, $the_query );
// query is made
query_posts($the_query);
// Reset and setup variables
$output = '';
$temp_title = '';
$temp_link = '';
$temp_date = '';
$temp_pic = '';
$temp_content = '';
$the_id = '';
global $post;
// the loop
if (have_posts()) : while (have_posts()) : the_post();
$temp_title = get_the_title($post->ID);
$temp_link = get_permalink($post->ID);
$temp_date = get_the_date($post->ID);
$temp_pic = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
if ( !$temp_pic ) {
$temp_pic = get_template_directory_uri() . '/images/not-available.jpg';
}
$temp_excerpt = wp_trim_words( get_the_excerpt(), 150 );
$temp_content = wp_trim_words( get_the_content(), 300 );
$the_id = get_the_ID();
// output all findings - CUSTOMIZE TO YOUR LIKING
$output .= "<article>";
$output .= "<div class='post-$the_id text-content'>";
$output .= "<a href='$temp_link'><h2>$temp_title</h2></a>";
$output .= "<i>$temp_date</i>";
$output .= "<br>";
$output .= "<p class='post-content'>";
if(isset($temp_excerpt)) {
$temporary_excerpt = substr(strip_tags($temp_excerpt), 0, 150);
if($temporary_excerpt){
$output .= $temporary_excerpt;
$output .= '...';
}
}else{
$more = 0;
$temporary = substr(strip_tags($temp_content), 0, 300);
if($temporary){ $output .= $temporary; $output .= '...'; }
}
$output .= "</p>";
$output .= "<a class='read-more-link clearfix' href='$temp_link'>Read More</a>";
$output .= "</div>";
if($temp_pic) {
$output .= "<div class='image-content'>";
$output .= "<img class='post-img-feat' src='$temp_pic'>";
$output .= "</div>";
}
$output .= "</article>";
endwhile; else:
$output .= "nothing found.";
endif;
wp_reset_query();
wp_enqueue_style( 'slippery-css' );
wp_enqueue_style( 'slippery-slider-css' );
wp_enqueue_script( 'slippery-js' );
wp_enqueue_script( 'pegasus-slider-plugin-js' );
return '<section id="news-demo">' . $output . '</section>';
}
add_shortcode( "news_slider", "news_slider_query_shortcode" );