Twitter
1.0
Limit-Post Add-On
13. July 2009 · Author: Dale Crum
92 Comments

Limit-Post Add-On

Limit-Post is one of the better WordPress post content limiters we have come across, both in terms of usability and size. Developed by labitacora.net Limit-Post provides excellent control over the post character-length and even adds the ability to create “read more …” link with a single line of code.

From labitacora.net: “We have developed a plugin for WordPress in order to control the maximum amount of characters displayed for an entry on the main page. If the set limit is surpassed a link to a page with the whole content will appear and the text on the entry will be chopped to that amount of characters, otherwise the content will be show[n] unchanged.”

It came to our attention not long ago that we needed to make use of the WordPress tag; get_the_content. For those unfamiliar, WordPress supplies two methods of displaying the post content through php;

Option#1: the_content(); – The more familiar method of displaying the post content
Option #2: get_the_content(); – The less familiar content tag which strips all html tags

Option #2 is useful for listing articles or news without interruption of paragraph breaks, block-quotes or links which can easily disrupt a strict layout. Not wanting to reinvent the wheel, we wrote a short addition to the Limit-Post plugin giving it the added feature of the get_the_content(); tag.

In the example below, the post content is displayed with all html stripped out, 320 characters in length and a continue link of “read more…”. For further instructions on the Limit-Post options please visit labitacora.net. Limit-Post is a very resilient plugin having remained functional since it’s inception in 2005 during the WordPress 1.5 era. It continues to function perfectly with WordPress 2.7.1.

Please note that because all html is stripped, it will be necessary to add paragraph tags around the content.

Example

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<p><?php get_the_content_limit(320, 'read more...'); ?></p>
<?php endwhile; endif; ?>

Installation

  1. Download the plugin and expand it.
  2. Copy the limitpost-addon folder into your plugins folder ( wp-content/plugins ).
  3. Log-in to the WordPress administration panel and visit the Plugins page.
  4. Locate the Limit Post plugin and click on the activate link.
  5. Replace the_content(); with the_content_limit(200, "continue..."); or
  6. Replace the_content(); with get_the_content_limit(200, "continue...");

92 Comments

  1. Doc4, it’s complicated because it pulls from a certain category, a featured article thing that includes thumbnails. Admittedly it’s a little messy but it’s a copy and paste from the the theme itself, not my doing =P

    [ Code Removed http://pastebin.com/FBN8k5sq ]

  2. I’m using your plugin and in the theme I downloaded it was originally only shown on the front index page, but I would like to use it on a sidebar. Problem is, the content has stopped limiting. It shows the entire post and I can’t figure out how to fix it. Strangely enough there’s no problems at all on pages. Nothing was changed in the coding so I don’t know what would cause it.

  3. Yul,

    How are you using the code for the plugin? Essentially you need to place the code below within a loop where you would like the text to appear.

    Replace:
    <?php the_content(); ?>

    With:
    <php get_the_content_limit(320, 'read more...'); ?>

    Full Example:

    <php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <php the_title(); ?>
    <p><php get_the_content_limit(320, 'read more...'); ?></p>
    <php endwhile; endif; ?>

  4. Sherry,

    I hadn’t heard this before. I will be happy to look into it.

  5. The TweetMeme Retweet Button plugin has a problem with the_content_limit when it is activated. Deactivating the plugin, refresh, re-activate the plugin, refresh and content shows as it should. Another plugin that has issues is the uniquefier.php plugin. It comes with a second version, uniquefierA.php, this version does not appear to have a problem with the_content_limit.

  6. Jasper,

    Add the ‘read more’ echo into the additional elseif and else located in the ‘limit-post.php’ file. Give this a try.

    function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);
    
       if (strlen($_GET['p']) > 0) {
        echo $content;
            echo "...";
            echo "<br>";
            echo "<div class=";
        echo "'read-more'>";
        echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a></div></p>";
       }
       else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo $content;
            echo "...";
            echo "<br>";
            echo "<div class=";
        echo "'read-more'>";
        echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a></div></p>";
       }
       else {
          echo $content;
            echo "...";
            echo "<br>";
            echo "<div class=";
        echo "'read-more'>";
        echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a></div></p>";
       }
    }
    

  7. Jasper says:

    Cheers mate this is a fantastic update to the plugin I’ve been using for a long time. Looks like the original author’s site is now dead, so good thing you came along. I like how it now supports non-stripped HTML tags.

    My question is this: How can we force the plugin to display the “read more” link no matter what? In other words, even if there is no overflow of words in a post, how can we force the $more_link_text code to appear always?

    Thanks much and good luck to you. I will wait your reply.

  8. Eero,

    To place the ‘read more’ on the same line open the limit-posts.php file (located within the plugin folder) and remove the break <br> tag. This might not work 100% with the second get_the_content_limit version but should with the_content_limit. To add right alignment use the div class included of ‘read-more’.

    
    echo "...";
    echo "<br>"; // remove this entire line
    echo "<div class=";
    echo "'read-more'>";
    echo "<a href='";
    the_permalink();
    echo "'>".$more_link_text."</a></div></p>";

    Add to your styles.css

    .read-more {
       text-align: right; // you might also try - float: right;
       }

  9. Eero says:

    Hi,
    How can I change the alignment of the ‘read more’ text? So it will appear on the same line as the last line of the shortened text (or the next line, if the last line of the content is full) but with the right alignment?
    thanks

  10. Mike,

    I’m not sure how to make this any more clear, but if you have a suggestion I will be happy to include it in the post. Replace the_content(); with the_content_limit(200, “continue…”);. The code to replace is located within the theme files. Access these files by visiting Appearance > Editor, then scan through the list of php files to find the location where the new code should be placed.

  11. Mike says:

    I have installed the plugin. But I have no idea how to change the_content_limit(200, “continue…”); etc…?

    Where? There needs to be better and clearer explanation about this.

  12. Sean says:

    @Doc4 I believe you want:

    
    .read-more a {
       color: #333333;
       text-transform: uppercase;
       }
    
    .read-more a:hover {
       color: #465782;
       }
    

    :)

  13. Donny,

    The plugin creates an new div tag around the read-more link which i then controlled through CSS. Try addingt he following styles to your style.css file.

    .read-more a {
       color: #333333;
       text-transform: uppercase;
       }
    
    .read-more a:hover
       color: #465782;
       }

  14. Donny says:

    Sorry for this stupid question but, how can i change the color of the “Read More” link? I’m looking anything on my css and and everywhere on my php files. But didn’t found any luck.

    Im using creativepress wordpress themes from web2feel by the way..

  15. you plugin is work on my theme… with this code the_content(); with get_the_content_limit(200, “continue…”);

    while I’m trying using the first code my css trashing and my sidebar was drop down the page. so I’m decide to using the second ones and it’s work. Tq very mush.

  16. Lesha,

    One downfall of this plugin is that it counts some code as characters. For example a link ( <a href="mylink.com">The Link</a> ) would be counted as 31 characters and not the 7 ( The Link ) you would expect. The best thing to do is use get_the_content instead of the_content to remove all code from the text.

  17. lesha says:

    hello .
    i love your plugin. it works well on my wordpress.
    but i meet some minor problem,.

    now my content limit i set as 200 . but if i have a post the word length is short than 200 , and follow with a gallery(wordpress default gallery function) . it will automatically show another readmore tag.

    i had screenshot it >>>>>>>> http://picasaweb.google.com/lh/photo/-eW4Z_I0XNx0Qwkmo24MHw?feat=directlink

    did anyone know how to fix this???
    thanks :)

  18. Thanks for the plugin. Been looking for something like this all day. Work perfectly on one of my blog. Thanks

  19. Why the hell no one can say WHERE and WHICH index.php this is where the_content(); should be replaced? Is it really too much to ask?! I have never used WP since yesterday, therefore I don’t know these things! Sorry I’m really $*&%$ off for now – I’ve been struggling with it and guessing from the beginning without knowing what damn index.php you all are talkin’ about!

  20. Max,

    The only index.php you should be altering is the theme’s index.php file. Look here: wp-content > themes > “your theme name” > index.php. Hope this helps.

  21. Kelly Rainmaster,

    Can you demonstrate how you are implementing the code on the index.php file.

    <?php the_content(); ?> should be replaced with something similar to <php get_the_content_limit(320, 'read more...'); ?>

    What were your intentions in editing the plugin file?

  22. Kelly Rainmaster says:

    Please help.

    Your plugin does not work at all for me.
    The home page with posts is not changed.

    Loaded plugin.
    Edited limit-post.php

    ‘, ‘]]>’, $content);

    if (strlen($_GET['p']) > 0) {
    echo $content;
    }
    else if ((strlen($content)>$max_char) && ($espacio = strpos($content, ” “, $max_char ))) {
    $content = substr($content, 0, $espacio);
    $content = $content;
    echo $content;
    //echo “<a href='";
    //the_permalink();
    echo "…";
    echo "”;
    echo “”;
    echo “”.$more_link_text.”";
    }
    else {
    echo $content;
    }
    }

    function get_the_content_limit($max_char, $more_link_text = ‘(120, more…)’, $stripteaser = 0, $more_file = ”) {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters(‘get_the_content’, $content);
    $content = str_replace(‘]]>’, ‘]]>’, $content);
    $content = strip_tags($content);

    if (strlen($_GET['p']) > 0) {
    echo $content;
    }
    else if ((strlen($content)>$max_char) && ($espacio = strpos($content, ” “, $max_char ))) {
    $content = substr($content, 0, $espacio);
    $content = $content;
    echo $content;
    //echo “<a href='";
    //the_permalink();
    echo "…";
    echo "”;
    echo “”;
    echo “”.$more_link_text.”";
    }
    else {
    echo $content;
    }
    }

    ?>

  23. Aileen,

    Can you send me your index.php file so I can see the code you are using, I see a rouge <em></em>? Also, add </em> to the list of ending tags in the plugin. This plugin doesn’t support paragraph numbers just character-length.

    UPDATE: the issues have been resolved by adding additional ending tags to the code as mentioned above.

  24. Thank you for the file, Doc4.

    I have 1) Deactivated the plug-in 2) deleted the original and uploaded the new file 3) activated the plug in.
    However, the same problems persist. Most of my posts are either turned to italic or bold fonts and many posts are shown in a cell of a table. Also, hyperlinks are crossed out. You can see them on my website.
    I have tried with several different themes, but I get the same result…

    Actually, the same problem happens when I try to use WP Limit Posts Automatically (“WPLPA”) plug-in. With WPLPA, unless I choose paragraph option, if I choose to limit posts by words or characters, the same problem happens as with your plug in.

    Doc4, if you don’t mind, could you please tell me how I can change the codes to display 2 Paragraphs instead of, say, 400 words? Judging from my exprience of playing around with WPLPA, it seems paragraph display somehow fixes this formatting run-over problem, however, I want to show 2 paragraphs not 1 paragraph.

    Thank you for your patience and kindness.

    Aileen

  25. Aileen,

    That would be a mistake on my part. The change should be on lines 31 and 59. I’m emailing a a file to you.

  26. Aileen says:

    Doc4,
    Thank you for your kind instruction. Honestly, I don’t think I know how to follow your instruction especially for Line 38.

    I changed Line 59 from
    echo “‘>”.$more_link_text.”";
    to
    echo “‘>”.$more_link_text.”";

    However, I don’t know how to change line 38. Line 38 is:
    function get_the_content_limit($max_char, $more_link_text = ‘(more…)’, $stripteaser = 0, $more_file = ”) {
    So, where in this line should I add
    echo “‘>”.$more_link_text.”";

    Thank you very much for your kindness.

    Aileen

  27. shoaib hussain says:

    thnx for such a nice plugin..works just perfectly for me…

  28. Aileen,

    By adding your ending tags such as “” into the Limit-Post code you effectively cut off any open tags that are spilling over into the next post.

    echo "'>".$more_link_text."</a> “” is the end of the more link text regardless of whether it is being used or not.

    </strong></i></div></p>"; are ending tags that begin within the post. Limit-Post does not stop all tags which is why your posts are bleeding italics and bolds.

    Please give this a try and you should see the results needed.

  29. Aileen says:

    Thank you. But, I think you have mis-understood me. It is about shortened post that I had trouble with. I didn’t try to make more link bold or italic… Thanks, anyways.

  30. Aileen,

    Please add additional ending tags to the limit-post.php file. Lines 31 and 59 can be modified with additional information.

    Line 31: echo "'>".$more_link_text."</a></strong></i></div></p>";

    The above alteration adds ending tags to Italicized and Bold fonts.

  31. Aileen says:

    Thank you very much for your help, Doc4.
    I have changed Category, Index, and Search to 600 characters. However, I get a big problem with formatting.. You can come to http://www.uprofish.com to see, but

    1) On the main page, everything below 5th post is displayed in italic fonts.
    2) If you go to page 3 of the main page (www.uprofish.com/page/3), you can see that all posts are shown as part of a table’s cell.
    3) Many hypertext links are dissplayed crossed out. Please come http://www.uprofish.com/category/understand/korea/ and see the bottom post. Also, the top post on http://www.uprofish.com/page/3.
    4) If you see http://www.uprofish.com/category/profit/ you can see that the bottom 3-4 posts are all displayed in bold fonts.

    Is there any way to fix this formatting problems?
    I tried using different themes, but the result is always the same…

    Thank you.

  32. Aileen,

    You will be replacing this line: <?php the_content(); ?> found in files such as “index.php”, “single.php”, “archive.php” and possibly others depending on how the theme files are set up. These files are accessible from the WordPress dashboard: Appearance > Editor or via an FTP (File Transfer Protocol) program such as Transmit by visiting wp-content > themes > default (or your theme name). The content tag is used to display post content from the text editor field (a.k.a. Tiny MCE Editor). For more information on the_content tag please see: http://codex.wordpress.org/Template_Tags/the_content. Hope this helps, please let us know if you need more information or assistance with inserting the code into your files.

  33. Aileen says:

    Hi,

    Thanks for the plug-in. This is exactly what I needed, but I am a complete novice…

    Could you please tell me in which file I am supposed to follow the below instruction?
    Replace the_content(); with the_content_limit(200, “continue…”); or
    Replace the_content(); with get_the_content_limit(200, “continue…”);

    I could certainly not find it it in your Plugin code. Is it in my wp directory??

    Thank you for your help.

    Aileen

  34. To keep everyone in the loop. We believe there to be a conflict between FCKEditor and the Limit-Post plugin. If possible try incorporating TinyMCE Advanced as an alternative.

  35. Frank says:

    Sorry… The problem still there!.

  36. Frank says:

    Thanks for your suggestion… I’ll try it immdiately.
    Ciao.

  37. Frank,

    Try deactivating all plugins except Limit-Post and see if the issue still occurs. If not, there is a plugin conflict which you can locate by activating the plugins one by one until the problem occurs again.

  38. Frank says:

    Good evening
    after installing your plugin, I noticed that actually breaks up the text, but, unfortunately, completely replace the two sidebar under the end of the post and, among other things, make the font bold some text comments.
    I note that I have installed the editor FCKEditor For WordPress.
    Any suggestions, please?.
    Greetings and thank you very much!
    Frank

  39. Jordan,

    To retain HTML tags use <php the_content_limit(320, 'read more...'); ?> note the removal of “get_”

  40. Hey would there be any possible way to include some HTML elements in the Limit (I want to keep tags within the shortened exerpt.

    Thanks for the great plugin

  41. Hi
    I don’t recived anything from U…

  42. Hi

    Not worked :(

    I found plugins (WP Limit Posts Automatically) This plugin limited all post without any problems , But my problem is with post who comes from rss feed , they come to my blog without limited i mean ( when the post come by rss to my blog i want something to limited them EX:

    1)title : My First day

    2) Contents : yes it’s my first day in New york , i’m happy to be here (Read more … )

    If U take a look Up u can see the contents finished by (Read more … ) I want this point (limited all post Rss and my post)

    I upload the single.php file of my them : http://rapidshare.com/files/322755370/single.php.html

    if u need anything i ready for that …

    thanks

  43. Tom,

    Limit-Post will only function with content written within the tiny mce post editor and will not function with RSS feeds. This is because we are using a modified version on <?php the_content(); ?> which, created by the developers of WordPress, simply locates a posts content form the editor.

    I’m not sure I understand what you mean: “all the Contents post Falls without limited (Read more..)”

    You can try the following to be certain things are running correctly. Replace an instance of <?php the_content(); ?> with <?php get_the_content(); ?> and be sure this pulls the content in with no formatting from the editor itself. If this works correctly please let us know and we will be happy to contact you via email and if willing to send us a copy of the file you are working on so we can take a better look.

  44. Hi

    I found the code and replace it, but nothing happened :( Some of the post comes in my blog by rss and all the Contents post Falls without limited (Read more..)

    I Don’t Know if your plugin work for this or not … I get many plugins but no one worked. U can take a look on my blog and see some post are here without limited and some of then is posted by me and i limited them by read more Options when i write the post. crazyegg.net

    Thanks

  45. Babloo,

    The code should look like this:

    <php get_the_content_limit(320, 'read more...'); ?>

    Double check it and if it still does not work correctly please send the page with the code to us and we will take a look.

  46. i got some thing like u said and i tried to config it and the page is not loading,mine theme is a magazine theme can u help me with this?

  47. dan,

    Yes after replacing “the_content();” with one of the new options the post would be shortened once the plugin is activated. “the_content();” is the WordPress function used to display the content written within a post. This code is generally found within the WordPress loop which is located within the theme files. For example: open single.php and search for “the_content();”.

  48. how to performed step 5/6 below? change the plugin code? where is “_content()”? then would posts be shortened automatically after activation?

    thx

    1. Download the plugin and expand it.
    2. Copy the d4-limitpost-addon folder into your plugins folder ( wp-content/plugins ).
    3. Log-in to the WordPress administration panel and visit the Plugins page.
    4. Locate the Limit Post plugin and click on the activate link.
    5 Replace the_content(); with the_content_limit(200, “continue…”); or
    6. Replace the_content(); with get_the_content_limit(200, “continue…”);

  49. Rabbitdk,

    Send me the file you would like to make changes to and I will be happy to take a look.

    Update: Files sent to Rabbitdk – Glad I could help.

    Thanks

  50. Rabbitdk says:

    Hi there.

    Addon is just what I am looking for, but I can’t make it work. I can’t find the_content(); anywhere, hence I can’t replace it .D

    Kind regards…

Trackbacks

  1. How To limit the displayed text length on your Homepage - WordPress Plugin | MindPrompter.com
  2. Limit-Post Add-On | Doc4 | WpMash - WordPress News
  3. wp-popular.com » Blog Archive » Limit-Post Add-On | Doc4
  4. [ Plugin ] Limit-Post Add-On - WordPress Tavern Forum
  5. [ Plugin ] Limit-Post Add-On - WordPress Forums

Leave A Comment

Please wrap any code within the <code> tag to display properly

Incorporating animals into identities is not a groundbreaking topic by any means but making the design work on a professional level isn't always an easy task. Making use of an artist's...

It's Christmas time, so I thought I would have a little fun with my article this month, not that I don't usually have fun. Since we are all designers, what better topic to discuss than...

After reading hundreds of articles and design newsletters over the years showcasing websites as a source of inspirational material we felt it was our turn to give back to the community....

When you own a small business, competing with the top dogs in the market can be a financial and time-consuming challenge. How do you get the word out about your business without spending...

If you are reading this article then you are probably a graphic designer or work in marketing in some form or fashion. That being said, you probably own your own company, freelance,...