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.

Condensed Content v0.93

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.

71 Responses to “WordPress Plugin: Condensed Content for Date and Category Archives”

  1. Binary Bonsai Says:

    Condensed content
    I’ve started using the Condensed content for date and category archives WordPress plugin.

  2. yves Says:

    hello Rich,
    I tried your plug-in. It seems it does not work with the Wordpress last version
    Regards
    Yves

  3. Rich Manalang Says:

    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?

  4. Ben Says:

    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.

  5. Muse Says:

    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%/

  6. Rich Says:

    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?

  7. Muse Says:

    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. :)

  8. Muse Says:

    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

  9. Ben Says:

    I cannot get it to work either.
    Is it possible to write a version for the default Wordpress 1.2 installation?

  10. Rich Manalang Says:

    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.

  11. Rich Manalang Says:

    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?

  12. Muse Says:

    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 doesn’t really matter… I’m just glad I’ve 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.

  13. Rich Manalang Says:

    I’ve just posted a newer version of this plugin above. This newer version fixes issues with WordPress installations that don’t use the permalinks feature or have custom permalinks structures.

  14. Muse Says:

    Sweet! Working like a charm now. Thanks, Rich!

  15. Muse Says:

    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?

  16. Muse Says:

    Ah, finally found it after a few unsuccessful tries. :)
    $excerpt .= ($use_more_link_text) ? '...

    ‘.$more_link_text.’

    ‘ : ”;

    Youc an add whatever you want before the first p tag. :) Thanks again for this cool plugin.

  17. Rich Says:

    Muse, you don’t have to do that… you can make the change to line 18 instead:

    $more_link_text='Continue reading »’;

  18. Neil Uchitel Says:

    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.

    < ?php the_content(); ?>
  19. Luc Says:

    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

  20. Rich Says:

    Luc, I just posted a new version. Check it out… it should work for you.

  21. Netlex News » Condensed Content v0.92 Says:

    [...] Wordpress — site admin @ 1:57 am  (Current Mood: )

    WordPress Plugin: Condensed Content for Dat [...]

  22. nate Says:

    I guess I don’t understand why you stripped the HTML tags. I like ‘em and commented the line that stripped them out.

  23. Karl Bedingfield Says:

    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

  24. James Says:

    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 :)

  25. Karl Bedingfield Says:

    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

  26. James Says:

    Change line 49 from:

    `return “

    $content

    “;`

    to:

    `return “

    $content

    “;`

  27. Mongrol Says:

    Great plugin, but is there any way to miss out certain categories?

  28. Mongrol Says:

    Ah, got around it by putting a little if statement in the condensed.php

  29. OneWoman Says:

    Very nice! Works like a charm.

  30. David Eyk Says:

    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!

  31. indi Says:

    Thank you, it works great. It’s nice to find a plug-in that’s really plug and play.

  32. Tom Says:

    What do I do if I don’t want the comments tag to show up on archive pages using condensed content?

  33. Chris Says:

    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..

  34. Chris Says:

    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. :oops:

  35. Alex Says:

    Installed WP 1.21, enabled permalinks, uploaded condensed_content.php, activated.

    Doesn’t do anything.

    Any ideas?

  36. Ben Says:

    “I guess I don’t 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,

  37. Ryan Says:

    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!

  38. Lorelle VanFossen Says:

    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

  39. Blog - Journal Thoughts » WordPress Plugins and Add-ons Says:

    [...] n. Manalang&# [...]

  40. Andrea Says:

    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?

  41. Rich Says:

    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!

  42. Andrea Says:

    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?)

  43. cb Says:

    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

  44. cb Says:

    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_tags

    to

    $content = strip_img

    at any rate. works for me.

    thanks! lovin’ your plugin.
    -cb

  45. Nand kishor Says:

    Can someone tell me How do I turn on permanent Link, I am using wordpress 1.2.2

  46. Gordon Says:

    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.

  47. Morgs Says:

    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?

  48. Morgs Says:

    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:

    Q: On the archive pages, all HTML seems to have been stripped out of my entries! Also, only part of the entry is shown!
    A: That’s because the archives uses a function called the_excerpt. If you want to change it, so that it behaves like the frontpage, go to line 229 in index.php and change from < ?php the_excerpt() ?> to < ?php the_content('Read the rest of this entry »'); ?>.

    Thanks for a wicked plugin.

  49. LcF Says:

    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.

  50. LcF Says:

    Sorry. I mean:
    “or I use the &lt–more–&gt,…”

  51. Linda Bruton Says:

    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!

  52. Gordon Says:

    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.

  53. Emily from How to Blog Says:

    Does this plugin work with WP 1.5?

  54. Emily from How to Blog Says:

    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’.”

  55. Alejandro Nogales Says:

    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.

  56. Vernon Kesner Says:

    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!

  57. Vernon Kesner Says:

    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.

  58. blake Says:

    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?

  59. pregnantboy Says:

    it will be in future compatible with wordpress 2.0?

  60. Dan Butcher Says:

    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.

  61. wper Says:

    Ha, I’ll try it.

  62. http://www.wealthontap.com Says:

    I would like to use this with my WP2 Blog too…

  63. austin texas personal injury lawyer Says:

    i can’t seem to get the plugin to work.

  64. Alfredo Says:

    Thanks for the plugin! Bookmarked it now and will add it to my blog soon :)

  65. izlesene Says:

    Ha, I’ll try it.

  66. onegirlrtw Says:

    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!

  67. factor Says:

    I can’t get it work with WP 2.1.2 :(

  68. Eddie Says:

    Hi there! Just couldn’t resist your guestbook! Visit my sites, please:

  69. Rose Says:

    Nice page greetings to all in this guestbook! Would you please also visit my homepage?

  70. Blair Says:

    Good site, nice design! Please visit my site too:

  71. Scudfish Says:

    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

Leave a Reply