WordPress Plugin: Condensed Content for Date and Category Archives
Update: I’ve just posted a newer version of this plugin below. This newer version fixes issues with WordPress installations that don’t use the permalinks feature or have custom permalinks structures.
On my old MT weblog, my monthly and category archives only displayed the first 30 words of an entry in order to prevent large date or category archive pages. I wanted to implement that feature on this weblog but couldn’t find a way to do it with the delivered template tags, so instead, I wrote a plugin to do just that. Here’s an example of a condensed category page.
Download the file above to your wp-content/plugins directory, rename it to condensed_content.php. Then within the WordPress Plugin admin inteface, activate the plugin.
This plugin applies a filter to the_content() which will trim the post entry to the set number of words. The number of words to display is configured in the plugin code itself — the variable is called $cut_at. On top of trimming the post entry, it also strips any HTML tags that may be in the post entry.
May 30th, 2004 at 8:42 AM PDT
Condensed content
I’ve started using the Condensed content for date and category archives WordPress plugin.
June 6th, 2004 at 1:14 PM PDT
hello Rich,
I tried your plug-in. It seems it does not work with the Wordpress last version
Regards
Yves
June 6th, 2004 at 11:37 PM PDT
what problem are you experiencing? I’ve tested this on WP 1.2 and it seems to work just fine. Do you have permalinks turned on?
June 17th, 2004 at 8:40 PM PDT
Thank you for this nice plugin. I got it working fine once I enabled permalinks. I suppose, as youv’e already suggested, that’s yves’ problem as well.
June 18th, 2004 at 5:05 AM PDT
I installed it with no problem, but no matter what I did, I could never click on the post title to get the full post. It kept giving me the condensed version. I’m using mod rewrite to get nicer looking permalinks… but I’m using the post ID rather than the slug/postname. Could that be it?
/archives/%year%/%monthnum%/%day%/%post_id%/
June 18th, 2004 at 12:28 PM PDT
Muse, are you using get_permalink() as to get your permalink URL (look in your template)? If not, you’ll need to modify line 54 in the plugin and replace the get_permalink() function with whatever you’re using to generate your permalink URL. Make sense?
June 19th, 2004 at 9:14 AM PDT
Ah, yes it does make sense. The template (just a modified version of the default one.. I didn’t mess with the functions much because I just started with WP) is using the_permalink() function. I’ll edit the plugin and see if that helps.
Thank you for the response and the cool plugin.
June 19th, 2004 at 9:19 AM PDT
Well, if I use the_permalink() in the plugin, not only does it not work like before, but I also get the full url at the beginning of the “excerpt” on an archive page. If I change from the_permalink to get_permalink in my index.php, then all of my titles simply link to the index page and not to the individual post itself.
I wonder why I’m having so much trouble. LOL
June 19th, 2004 at 1:46 PM PDT
I cannot get it to work either.
Is it possible to write a version for the default Wordpress 1.2 installation?
June 19th, 2004 at 5:53 PM PDT
Try changing get_permalink() in the condensed_content.php plugin to the_permalink(). Let me know what happens… if that fixes it, I’ll post an update.
June 19th, 2004 at 5:55 PM PDT
Ben, this was written for the WP 1.2 default installation. I’ve verified that this on a vanilla WP 1.2 install. What problem are you encountering?
June 20th, 2004 at 4:16 AM PDT
Rich,
Did you mean something different than what I’ve already done? I apologize if I don’t quite understand. I already tried changing the plugin on the line you specified to say the_permalink so it would match my template (which is the default one that comes with WP 1.2 and uses the_permalink). For each excerpt on an archive page, I got an unclickable URL which matched the url of the page at the beginning of each excerpt. And I still couldn’t get the full post by clicking on anything. Here’s an example of an excerpt I get on a “category archive” page:
http://www.wickedmuse.net/archives/2004/06/17/6/ I forgot how I discovered Rox Populi. It doesnt really matter Im just glad Ive found her. About a week or so ago, she put up a post concerning the …
Just like that. And when I click on the title of the post, it just takes me to the individual archive that’s also condensed and there’s no way to expand it.
So, I’ve tried the_permalink in both the plugin and the index.php, as well as get_permalink in both the plugin and index.php and none of the combinations seem to work. I haven’t modified my WP1.2 installation beyond installing some plugins and customizing the CSS.
June 20th, 2004 at 8:36 PM PDT
Ive just posted a newer version of this plugin above. This newer version fixes issues with WordPress installations that dont use the permalinks feature or have custom permalinks structures.
June 21st, 2004 at 3:32 AM PDT
Sweet! Working like a charm now. Thanks, Rich!
June 21st, 2004 at 3:52 AM PDT
What can I add into the plugin code so I can get something like [...] at the end of the condensed entry instead of it just cutting off?
June 21st, 2004 at 3:58 AM PDT
Ah, finally found it after a few unsuccessful tries.
Thanks again for this cool plugin.
$excerpt .= ($use_more_link_text) ? '...
‘.$more_link_text.’
‘ : ”;
Youc an add whatever you want before the first p tag.
June 21st, 2004 at 12:04 PM PDT
Muse, you don’t have to do that… you can make the change to line 18 instead:
$more_link_text='Continue reading »’;June 24th, 2004 at 7:45 PM PDT
Hi Rich,
Installing the plug in causes the design of the content portion to go haywire. How or where do I add the code to make sure it formats these condensed versions with the right css div. Here’s my code that I need to put in there somewhere.
June 30th, 2004 at 3:07 PM PDT
Hello,
Condensed content worked very well untill last CVS update.
Now the error is
Fatal error: Cannot redeclare class wp_query_state in /home/sainteli/www/sandbox/wp-content/plugins/condensed_content.php on line 48
This seems to be related to last update of wp-blog-header.php
see http://cvs.sourceforge.net/viewcvs.py/cafelog/wordpress/wp-blog-header.php?r1=1.73&r2=1.74
June 30th, 2004 at 4:04 PM PDT
Luc, I just posted a new version. Check it out… it should work for you.
July 4th, 2004 at 11:57 PM PDT
[...] Wordpress — site admin @ 1:57 am (Current Mood: )
WordPress Plugin: Condensed Content for Dat [...]
July 11th, 2004 at 2:19 PM PDT
I guess I don’t understand why you stripped the HTML tags. I like ‘em and commented the line that stripped them out.
July 28th, 2004 at 2:07 PM PDT
Hi there,
Great plugin - using with WP1.3 and working well
I see that you are using it on your main entry index page. How do you do that?
I would like abbreviated entries when the user first goes to my site.
Thanks again
Karl
July 29th, 2004 at 4:28 AM PDT
I love this plugin, very neat and worked first time (unusual for me).
One tiny suggestion though, on the next update could you change the link text to something like
$more_link_text='Continue reading ‘.get_the_title().’ …’;, the symbol at the end isn’t important, but including the title means that your category or archive page isn’t filled with links using exactly the same text.Just an accessibility thing
August 6th, 2004 at 8:39 AM PDT
I love this but alas I have found a bug that related to the WP1.3A2 release.
When I activate this plugin and view my code the plugin created another ser of paragraph tags around the entry. So for example you would get this@
< p > < p > this is a test < / p > < / p >
Any ideas on how to fix this?
Thanks
Karl
August 9th, 2004 at 7:05 AM PDT
Change line 49 from:
`return “
“;`$content
to:
`return “
$content
“;`August 11th, 2004 at 12:26 PM PDT
Great plugin, but is there any way to miss out certain categories?
August 11th, 2004 at 12:48 PM PDT
Ah, got around it by putting a little if statement in the condensed.php
August 16th, 2004 at 9:20 AM PDT
Very nice! Works like a charm.
September 11th, 2004 at 1:36 AM PDT
Excellent plugin, first off. However, it was breaking my validation. Turns out it was this line:
return "$content
“;
This was wrapping a
around each post on my main page, and you can’t nest paragraphs in XHTML. The W3C validator was saying very nasty things about me, my mother, and my website. So, a fairly simple solution:
$excerpt = str_replace(']]>', ']]>', $excerpt);
$content = '
‘.$excerpt.’
‘;
}
return “$content”;
This way, the
wrapper only gets put up if the If clause gets triggered, in which case it’s safe to do, since you’ve already stripped any markup that’s left. Hope this helps!
September 23rd, 2004 at 3:03 PM PDT
Thank you, it works great. It’s nice to find a plug-in that’s really plug and play.
September 23rd, 2004 at 11:22 PM PDT
What do I do if I don’t want the comments tag to show up on archive pages using condensed content?
October 8th, 2004 at 12:16 AM PDT
I really like your condensed content, I’m not sure if you’re still updating it or not but I was wondering if you were aware that if a post was password protected, an excerpt is still shown..
October 8th, 2004 at 12:23 AM PDT
I’m embarrassed, I was doing 3 things at once. What I meant to say or ask is there a way to get the excerpt to show or the form. The excerpt showing thing was a problem with another plug-in.
October 18th, 2004 at 2:55 PM PDT
Installed WP 1.21, enabled permalinks, uploaded condensed_content.php, activated.
Doesn’t do anything.
Any ideas?
October 19th, 2004 at 7:17 AM PDT
“I guess I dont understand why you stripped the HTML tags. I like em and commented the line that stripped them out.”
Which line is it that stripped them out?
As I’d like html to be included still - how do I do this?
Thanks,
October 22nd, 2004 at 4:35 PM PDT
Just started using it on my site. Using WP 1.21, works great! I may end up modifying it a bit, but for now I like it the way it is.
Thanks a lot!
November 4th, 2004 at 1:04 AM PST
I’m giving the plugin a try and you mention to “turn on permalinks”. How and where do you “turn it on” or do all the anchors need to be manually changed to ?php permalink_anchor() ?
Thanks,
Lorelle
November 6th, 2004 at 6:56 AM PST
[...] n. Manalang [...]
November 20th, 2004 at 12:57 PM PST
Hi, I downloaded your plugin and tried it out at my blog. Worked great, but in the end I decided to implement a tweak suggested here, to get a list of entry links and their excerpts on the category pages. I would still like to use condensed posts on monthly archives though, if that was possible. Is there any way to use the plugin just on certain pages, not all?
November 22nd, 2004 at 7:02 PM PST
Andrea, yes it’s possible. You’ll have to edit the code (line 30 to be exact) and replace the following line:
if ($qs->archive) {
to
if ($qs->date) {
That’s it. Cheers!
November 24th, 2004 at 4:46 PM PST
Thanks much, Rich. I’m playing around with the code right now and have yet another question. Can I opt to not include the ‘comments’ links below the condensed post, to keep the archive pages as uncluttered as possible? I tried the “let’s set this to false and see what happens” way, but it’s obviously not working. Thanks for any help!
(As an aside, I out-commented the tag-stripping line like the person above and found that eliminating HTML tags makes sense for posts that start with long image tags, but since my posts are rather link-heavy, the condensed versions look pretty funny. I know nothing about PHP and I was just wondering if there was any way to specify tags to exclude/include anywhere in the code?)
December 10th, 2004 at 6:05 AM PST
hi. hopefully you’re still reading the comments. i’m also using your auto archive feature.
i’d like to be able to strip image html tags, but keep the rest of the html going. is there any way to do that?
thank!
-cb
December 10th, 2004 at 4:32 PM PST
hey there. never mind. i think i figured it out. don’t know if this is completely correct, but somehow it works…this is to strip images from condensed archives, but not the rest of the tags. works great for link-heavy posts
add:
function strip_img($variable){
return(eregi_replace("
]*>”, “”, $variable));
}
before:
function condensed_content($content) {and then change:
$content = strip_tagsto
$content = strip_img
at any rate. works for me.
thanks! lovin’ your plugin.
-cb
December 29th, 2004 at 1:35 AM PST
Can someone tell me How do I turn on permanent Link, I am using wordpress 1.2.2
January 6th, 2005 at 10:26 AM PST
Nand - the permanent links are under the Options in your WordPress Admin.
Anyway, I’m just here to say thanks for this excellent little plugin. It’s the first one I’ve installed and tried and it’s great. Worked first time.
FYI - My index.php isn’t in my wordpress directory and the plugin also adds the condensed entries to my search results - doubly good!
Thanks for taking the time to create and maintain this. Mucho appreciato.
January 8th, 2005 at 9:18 AM PST
hello,
Thanks for the plugin. It is working for me, but not showing the continue reading text, is there something I am supposed to do for it to show this text?
January 11th, 2005 at 8:15 AM PST
Hello again,
I neglected to mention that I was using the kubrick template, and I have since found a fix to my problem which is very related to this fact. The answer can be found d: here on the Kubrick site, and goes something like this:
Thanks for a wicked plugin.
January 21st, 2005 at 2:26 PM PST
I installed it to WP1.2.2.
When my content is less than the $cut_at value or I use the < ! -- more -- >, it will remove the link as well.
January 21st, 2005 at 2:28 PM PST
Sorry. I mean:
“or I use the <–more–>,…”
January 28th, 2005 at 7:49 PM PST
Rick,
What a great plug-in! I just spent about 5 minutes installing it and it worked like a charm. I wish every script and piece of software I paid money for worked this easily. Thanks again!
February 14th, 2005 at 12:55 PM PST
Just a small note to add that if you are using custom permalinks (year/month/day/title) and your post doesn’t have a title, then the continue reading link won’t work (as it only has the ‘directory’ level to work with rather than a direct link via title).
Came across this issue on some older posts that I haven’t yet given titles to, might cause some confusion.
May 4th, 2005 at 12:36 PM PDT
Does this plugin work with WP 1.5?
May 4th, 2005 at 2:46 PM PDT
BTW - I just tried to subscribe to your comments feed in FeedDemon 1.5, and it says the feed does not validate, but that it would try to work around the error. It gave the following error msg, in case this helps you: “Line 74, Col 43: Reference to undefined entity ‘raquo’.”
September 15th, 2005 at 2:05 PM PDT
perfect!! but can this be adapted to the search results?
i hate how my search results are displayed and I haven’t found an edit… i searched for 4 hours.
September 28th, 2005 at 8:59 PM PDT
Thanks for this code! It does exactly what I was looking for and took about 2 minutes to get it up and running. Good stuff!
October 6th, 2005 at 9:04 PM PDT
Great plug-in first and foremost!
I wanted to be able to have my main entries condensed and I noticed that someone else was asking the same thing. Hopefully this quick fix will help.
In the condensed_content.php file, find the line of code that is :
if ($qs->archive || $qs->search) {
and change it to:
if ( !is_single() ) {
This will basically shorten the display of all your posts unless it is on the single post page. I also commented out the following line so that my original formatting was kept:
//$content = strip_tags($content);
Overall… once again… GREAT plug-in! I can’t believe this wouldn’t be included in the default installation.
November 2nd, 2005 at 1:04 PM PST
I love this plugin, it does exactly what I need, but everytime I install it I get all these messy headers in my wp-admin interface that read:
Warning: Cannot modify header information - headers already sent by (output started at /home/xxxx/public_html/news/wp-content/plugins/condensed_content.php:166) in /home/xxxx/public_html/news/wp-admin/admin.php on line 10
etc. etc. — they are “permanent” and appear on every admin page. Any idea how to fix?
January 8th, 2006 at 5:06 AM PST
it will be in future compatible with wordpress 2.0?
February 12th, 2006 at 7:11 PM PST
I’d like to second the request for an upgrade to WP2.0. This is a great plugin and I’d love to be able to use it with my site.
February 20th, 2006 at 7:53 AM PST
Ha, I’ll try it.
May 23rd, 2006 at 2:50 AM PDT
I would like to use this with my WP2 Blog too…
June 26th, 2006 at 12:26 PM PDT
i can’t seem to get the plugin to work.
January 20th, 2007 at 1:13 AM PST
Thanks for the plugin! Bookmarked it now and will add it to my blog soon
February 10th, 2007 at 1:23 PM PST
Ha, I’ll try it.
March 5th, 2007 at 7:16 PM PST
Thanks for the plugin mate…just trying to sort it out…excuse me for being a novice here, but the instructions are not so clear to me. Where do I insert the php code to get this working??
I have 2 archive files - Archives and archives…using the Dark Blix Widgetized theme. The archive.php for example looks like:
Posts filed under ”
Archive for
Archive for
Archive for
Search Results
Author Archive
Blog Archives
post_content); ?>
” class=”permalink” title=”Permalink”>
Not Found
Sorry, but you are looking for something that isn’t here.
So where do I insert your php code?? Thanks!
March 19th, 2007 at 3:55 AM PDT
I can’t get it work with WP 2.1.2
March 30th, 2007 at 3:43 PM PDT
Hi there! Just couldn’t resist your guestbook! Visit my sites, please:
March 30th, 2007 at 3:43 PM PDT
Nice page greetings to all in this guestbook! Would you please also visit my homepage?
March 30th, 2007 at 3:43 PM PDT
Good site, nice design! Please visit my site too:
April 12th, 2007 at 3:21 PM PDT
Same as factor,
I also can’t get it to work with 2.1.2. It would be great to see it revised.
But all in all, thanks for sharing.
SF