-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-gallery.php
106 lines (102 loc) · 2.73 KB
/
post-gallery.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
<?php
/*
Plugin Name: post gallery
Plugin URI: http://www.zeevm.co.il
Description: Creates a nice post gallery/post archive, uses a choosen category to show a grid list of posts with image, read more and the excerpt.
Version: 0.3
Author URI: ze'ev ma'ayan
Author URI: http://www.zeevm.co.il
/* TM zeev.co.il */
add_action('init', 'process_post');
//limit number of words in the text under the img
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
//create shortcode things
function process_post(){
function button_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'cat' => 'cat',
'onpage' => 'onpage',
'words' => 'words'
), $atts ) );?>
<ul class="zeevul">
<?php query_posts( array ( 'cat' => $cat, 'posts_per_page' => $onpage));
if (have_posts()) : while (have_posts()) : the_post();
// do whatever you want
?>
<li>
<h2 href="<?php the_permalink(); ?>"><?php the_title(); ?></h2>
<?php
if(has_post_thumbnail()) { ?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail();?></a>
</div>
<?php } else { ?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>"><img src="<?php echo plugins_url(); ?>/post-gallery-and-archive/default-img.png" alt="Image Unavailable" /></a>
</div>
<?php } ?>
<p><?php echo excerpt($words); ?></p>
<a href="<?php the_permalink(); ?>">Read More >></a>
</li>
<?php
endwhile;
wp_reset_query();
?><?php endif;
// style it up
?>
</ul>
<style>
ul.zeevul {
width:100%;
}
ul.zeevul li {
list-style:none!important;
float:left;
width:27%;
margin-left:2%;
margin-top:20px;
}
ul.zeevul li img{
width:100%;
height:150px;
}
ul.zeevul li img:hover{
opacity:0.6;
filter:alpha(opacity=60); /* For IE8 and earlier */
}
@media screen and (max-width: 1024px){
ul.zeevul li {
width:100%;
margin-left:0;
margin-top:5px;
}
}
</style>
<?php
}
Function archive() { return sheker();}
add_shortcode('post-gallery', 'button_shortcode');
}?>