1.0
doc4design.com - Limit-Post Add-On
13. July 2009 · Author: Dale Crum
30 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...");

30 Comments

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

  2. 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;
    }
    }

    ?>

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

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

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

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

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

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

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

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

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

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

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

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

  15. Frank says:

    Sorry… The problem still there!.

  16. Frank says:

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

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

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

  19. Jordan,

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

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

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

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

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

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

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

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

  27. 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();”.

  28. 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…”);

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

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

Leave A Comment

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

If you had to wear only one set of clothing to work everyday for the rest of your life, how much time would you spend considering what you are going to wear? You might take some time...

WordPress gives us so many options that it truly is amazing they have yet to declare themselves a Content Management System. Sometimes though we have to give the program a little nudge...

"The conscious and intelligent manipulation of the organized habits and opinions of the masses is an important element in democratic society... In almost every act of our daily lives,...

In this tutorial we will be covering a simple method of adding numbers to looped posts. An example usage of this technique is a search results page where the output may span multiple...

"I had this guy leave me a voice mail at work, so I called him at home, and then he emailed me to my BlackBerry, and so I texted to his cell, and then he emailed me to my home account,...