/
slider-18tags.php
executable file
·78 lines (71 loc) · 2.05 KB
/
slider-18tags.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
<?php
/**
* Plugin Name: Slider - 18tags
* Description: Adds a cool slider showing sticky posts on blog page
* Version: 1.0.0
* Author: pootlepress
* Author URI: http://www.pootlepress.com/
* @developer Shramee <shramee.srivastav@gmail.com>
* @package slider-18tags
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Pootle_Customisations {
public function __construct () {
add_action( 'wp', array( $this, 'wp' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
//exclude/include products in search
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
}
public function wp() {
if ( is_home() ) {
add_action( 'eighteen_tags_before_content', array( $this, 'homepage_slider' ) );
}
}
public function scripts() {
if ( is_home() ) {
wp_enqueue_style( 'slider-18tags-styles', plugin_dir_url( __FILE__ ) . '/assets/css.css', '', '4.2.5' );
wp_enqueue_script( 'slider-18tags', plugin_dir_url( __FILE__ ) . '/assets/jquery.bxslider.min.js', array( 'jquery' ), '4.2.5', true );
}
}
/**
* Removes or adds products CPT in search
* @param WP_Query $query
*/
public function pre_get_posts( $query ) {
if ( is_home() && $query->is_main_query() ) {
$query->set( 'post__not_in', get_option('sticky_posts') );
}
}
function homepage_slider() {
query_posts( array(
'posts_per_page' => -1,
'post__in' => get_option('sticky_posts'),
'meta_key' => '_thumbnail_id',
) ); ?>
<?php if ( have_posts() ) { ?>
<style>
.bx-slider{display:none;}
</style>
<ul class="bx-slider">
<?php
while ( have_posts() ) {
the_post();
echo '<li><a href="' . get_permalink() . '">';
echo '<span class="bx-caption">';
the_title( '<h1>', '</h1>' );
if ( has_excerpt() ) {
echo '<p>';
the_excerpt();
echo '</p>';
}
echo '</span>';
the_post_thumbnail( 'full', 'title="' . get_the_title() . '"' );
echo '</a></li>';
} ?>
</ul>
<?php
}
wp_reset_query();
}
} // End Class
new Pootle_Customisations();