Advanced Excerpt - Version 3.1

Version Description

  • Fix: A few bugs with custom and character-based excerpts
Download this release

Release Info

Developer basvd
Plugin Icon wp plugin Advanced Excerpt
Version 3.1
Comparing to
See all releases

Code changes from version 3.0 to 3.1

Files changed (2) hide show
  1. advanced-excerpt.php +13 -7
  2. readme.txt +13 -9
advanced-excerpt.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Advanced Excerpt
4
Plugin URI: http://sparepencil.com/code/advanced-excerpt/
5
Description: Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
6
- Version: 3.0
7
Author: Bas van Doren
8
Author URI: http://sparepencil.com/
9
@@ -123,7 +123,7 @@ class AdvancedExcerpt
123
{
124
// Merge custom parameters
125
if(is_array($this->custom_options))
126
- $r = array_merge($this->custom_options, $this->default_options);
127
else
128
$r = $this->default_options;
129
@@ -185,19 +185,24 @@ class AdvancedExcerpt
185
// Characters
186
187
// Count characters, not whitespace, not those belonging to HTML tags
188
- if($length > $this->strlen(strip_tags($text)))
189
return $text;
190
191
$in_tag = false;
192
$n_chars = 0;
193
for($i = 0; $n_chars < $length || $in_tag; $i++)
194
{
195
- // TODO: Improve this loop
196
-
197
$char = $this->substr($text, $i, 1);
198
// Is the character worth counting (ie. not part of an HTML tag)
199
if($char == '<')
200
$in_tag = true;
201
elseif($char == '>')
202
$in_tag = false;
203
elseif(!$in_tag && '' != trim($char))
@@ -209,7 +214,8 @@ class AdvancedExcerpt
209
}
210
$text = $this->substr($text, 0, $i);
211
}
212
- $text = force_balance_tags($text);
213
214
// New filter in WP2.9, seems unnecessary for now
215
//$ellipsis = apply_filters('excerpt_more', $ellipsis);
@@ -221,7 +227,7 @@ class AdvancedExcerpt
221
}
222
223
// Adding the ellipsis
224
- if(($pos = strpos($text, '</p>', strlen($text) - 6)) !== false)
225
{
226
// Stay inside the last paragraph (if it's in the last 6 characters)
227
$text = substr_replace($text, $ellipsis, $pos, 0);
3
Plugin Name: Advanced Excerpt
4
Plugin URI: http://sparepencil.com/code/advanced-excerpt/
5
Description: Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
6
+ Version: 3.1
7
Author: Bas van Doren
8
Author URI: http://sparepencil.com/
9
123
{
124
// Merge custom parameters
125
if(is_array($this->custom_options))
126
+ $r = array_merge($this->default_options, $this->custom_options);
127
else
128
$r = $this->default_options;
129
185
// Characters
186
187
// Count characters, not whitespace, not those belonging to HTML tags
188
+ if($length >= $this->strlen(preg_replace('/[\s]+/', '', strip_tags($text))))
189
return $text;
190
191
$in_tag = false;
192
$n_chars = 0;
193
for($i = 0; $n_chars < $length || $in_tag; $i++)
194
{
195
$char = $this->substr($text, $i, 1);
196
// Is the character worth counting (ie. not part of an HTML tag)
197
if($char == '<')
198
+ {
199
$in_tag = true;
200
+ if(($pos = strpos($text, '>', $i)) !== false)
201
+ {
202
+ $i = $pos - 1;
203
+ continue;
204
+ }
205
+ }
206
elseif($char == '>')
207
$in_tag = false;
208
elseif(!$in_tag && '' != trim($char))
214
}
215
$text = $this->substr($text, 0, $i);
216
}
217
+
218
+ $text = trim(force_balance_tags($text));
219
220
// New filter in WP2.9, seems unnecessary for now
221
//$ellipsis = apply_filters('excerpt_more', $ellipsis);
227
}
228
229
// Adding the ellipsis
230
+ if(($pos = strpos($text, '</p>', strlen($text) - 7)) !== false)
231
{
232
// Stay inside the last paragraph (if it's in the last 6 characters)
233
$text = substr_replace($text, $ellipsis, $pos, 0);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: excerpt, advanced, post, posts, template, formatting
4
Donate link: http://sparepencil.com/code/advanced-excerpt/
5
Requires at least: 2.2
6
Tested up to: 2.9
7
- Stable tag: 0.2.2
8
9
Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
10
@@ -14,7 +14,7 @@ This plugin adds several improvements to WordPress' default way of creating exce
14
15
1. It can keep HTML markup in the excerpt (and you get to choose which tags are included)
16
2. It trims the excerpt to a given length using either character count or word count
17
- 3. You can customise the excerpt length and the ellipsis character that will be used when trimming
18
4. A read-more link can be added automatically
19
4. The excerpt length is *real* (everything belonging to HTML tags is not counted)
20
5. Can ignore custom excerpts and use the generated one instead
@@ -26,7 +26,7 @@ This plugin is also compatible with Shortcodes.
26
27
Version 3.0 may not be backwards compatible. Check and re-apply the settings after you upgrade to make sure everything works correctly.
28
29
- Version 0.2.1 adds support for multibyte characters (eg. Chinese and Japanese). This is slightly experimental, more details in the FAQ.
30
Plugin translations are fully supported and language files are included for translation. The FAQ provides more info on this, also.
31
32
== Installation ==
@@ -42,11 +42,11 @@ After you've downloaded and extracted the files:
42
43
= Why do I need this plugin? =
44
45
- The default excerpt created by WordPress removes all HTML. If your theme uses `the_excerpt()` to view excerpts, they might look weird because of this (e.g. smilies are removed, lists are flattened, etc.) This plugin fixes that and also gives you more control over excerpts.
46
47
= Does it work for WordPress version x.x.x? =
48
49
- I haven't had the chance to test the plugin on many versions of WordPress. It has recently been tested on 2.9, but it might work on other versions, too. You can safely try it yourself, because the plugin is unlikely to break anything (it's only an output filter). Please let me know if you succesfully tested it on another version of WordPress.
50
51
= Is this plugin available in my language? / How do I translate this plugin? =
52
@@ -79,7 +79,7 @@ The following parameters can be set:
79
* `allowed_tags`, a comma-separated list of HTML tags that are allowed in the excerpt. Entering `_all` will preserve all tags.
80
* `exclude_tags`, a comma-separated list of HTML tags that must be removed from the excerpt. Using this setting in combination with `allowed_tags` makes no sense
81
82
- A custom, advanced excerpt call could look like this:
83
84
`the_advanced_excerpt('length=320&use_words=0&no_custom=1&ellipsis=%26hellip;&exclude_tags=img,p,strong');`
85
@@ -90,12 +90,16 @@ You can, however, consider to [start The Loop manually](http://codex.wordpress.o
90
91
== Changelog ==
92
93
= 3.0 =
94
95
- * Major release since 0.2.2 (also removed the `0.` prefix from the version number)
96
* Feature: Shortcodes can be removed from the excerpt
97
* Feature: Virtually any HTML tag may now be stripped
98
* Feature: A read-more link with custom text can be added
99
- * Fix: Word-based trimming speed improved
100
* Fix: Template tag function improved
101
- * Fix: Improved ellipsis placement
4
Donate link: http://sparepencil.com/code/advanced-excerpt/
5
Requires at least: 2.2
6
Tested up to: 2.9
7
+ Stable tag: 3.1
8
9
Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
10
14
15
1. It can keep HTML markup in the excerpt (and you get to choose which tags are included)
16
2. It trims the excerpt to a given length using either character count or word count
17
+ 3. You can customize the excerpt length and the ellipsis character that will be used when trimming
18
4. A read-more link can be added automatically
19
4. The excerpt length is *real* (everything belonging to HTML tags is not counted)
20
5. Can ignore custom excerpts and use the generated one instead
26
27
Version 3.0 may not be backwards compatible. Check and re-apply the settings after you upgrade to make sure everything works correctly.
28
29
+ Version 0.2.1 adds support for multibyte characters (e.g. Chinese and Japanese). This is slightly experimental, more details in the FAQ.
30
Plugin translations are fully supported and language files are included for translation. The FAQ provides more info on this, also.
31
32
== Installation ==
42
43
= Why do I need this plugin? =
44
45
+ The default excerpt created by WordPress removes all HTML. If your theme uses `the_excerpt()` to view excerpts, they might look weird because of this (smilies are removed, lists are flattened, etc.) This plugin fixes that and also gives you more control over excerpts.
46
47
= Does it work for WordPress version x.x.x? =
48
49
+ I haven't had the chance to test the plugin on many versions of WordPress. It has recently been tested on 2.9, but it might work on other versions, too. You can safely try it yourself, because the plugin is unlikely to break anything (it's only an output filter). Please let me know if you successfully tested it on another version of WordPress.
50
51
= Is this plugin available in my language? / How do I translate this plugin? =
52
79
* `allowed_tags`, a comma-separated list of HTML tags that are allowed in the excerpt. Entering `_all` will preserve all tags.
80
* `exclude_tags`, a comma-separated list of HTML tags that must be removed from the excerpt. Using this setting in combination with `allowed_tags` makes no sense
81
82
+ A custom advanced excerpt call could look like this:
83
84
`the_advanced_excerpt('length=320&use_words=0&no_custom=1&ellipsis=%26hellip;&exclude_tags=img,p,strong');`
85
90
91
== Changelog ==
92
93
+ = 3.1 =
94
+
95
+ * Fix: A few bugs with custom and character-based excerpts
96
+
97
= 3.0 =
98
99
+ * First major release since 0.2.2 (also removed the `0.` prefix from the version number)
100
* Feature: Shortcodes can be removed from the excerpt
101
* Feature: Virtually any HTML tag may now be stripped
102
* Feature: A read-more link with custom text can be added
103
+ * Fix: Word-based excerpt speed improved
104
* Fix: Template tag function improved
105
+ * Fix: Better ellipsis placement