Limit-Post Add-On

Limit-Post Add-On expands on the Limit-Post plugin from
labitacora.net by adding get_the_content(); as a text limiter.

DOWNLOAD DONATE
Description

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.

Because the developer's site is no longer functional we will keep this plugin updated for as long as possible. Below is the content from labitacora.net that was included with the original plugin, it's not much but here it is.

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

A practical case: Replace the line the_content() in the index.php file with: the_content_limit(1000, "Read more")

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 we are modifying a WordPress loop. The loop displays your post content and is located in many places throughout your WordPress theme. To begin, locate the PHP file containing the posts you wish to alter with Limit-Post and search for the loop within that file. The loop should look similar to the sample provided below.

For example, let's say you wanted to use Limit-Post on your Index.php (Also known as your Home Page or Main Index Template). Visit your WordPress dashboard and click on "Appearances > Editor" now locate "Main Index Template" from the list of files on the right hand side and search for the loop. Keep in mind that your theme may not be using the Main Index Template in a similar manner therefore you may need to search through other php template files (on the right hand side of this same page) until you find the loop you need. Once you have found the correct loop make the changes per the instructions.

In our example below the post content is displayed with all html stripped out, 320 characters in length and a continue link of "read more…". Change the variables [320] and [read more…] to suit your needs.

Example

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

DOWNLOAD DONATE
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...");

97 Comments, Questions & Answers

  1. I can't find the location in the code that you say to replace in the editor for this app.

    The code i have is:

    ', ']]>', $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_permalin();
    echo "…";
    echo "";
    echo "";
    echo "".$more_link_text."";
    }
    else {
    echo $content;
    }
    }

    function get_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('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_permalin();
    echo "…";
    echo "";
    echo "";
    echo "".$more_link_text."";
    }
    else {
    echo $content;
    }
    }

    ?>

    What should i replace to change the number of characters your app allows?

    • Colton,

      Thanks for contacting us to ask a question. The code you're looking for is this:

      <?php the_content(); ?>

      In the TwentyTen them these "Loops" are located int he loop.php file. So for example on line 142 of this php file:

      141 <div class="entry-content">
      142 <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
      143 <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
      144 </div><!-- .entry-content -->

      We might alter this to something like the following:

      141 <div class="entry-content">
      142 <?php get_the_content_limit(320, 'read more...'); ?>
      143 <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
      144 </div><!-- .entry-content -->

      Let me know if you need any additional help with this and sorry for the late reply. We've been out of the office due to the winter weather in our area.

  2. I have two main columns. Right-column & Left-column. When I use the php code () in my right column, everything lines up just as I'd like it. When I use the code , the right column all the sudden drops too low at the top. Looking at the html, it appears that it is missing an ending div tag when the content gets too long, so the left-column appears in the right-column. Any thoughts on how to fix this or why this would be happening?

    Thank you.

    • Bryan,

      Can you send the code of the page in question to info [at] doc4design.com and I'll take a look at it. Make sure you note where you would like the plugin to begin working. I have a feeling this is due to the plugin adding an extra closing div which means you may need to remove it from the plugin file. I'll post a better explanation once you send it over.

  3. Rob Commented On

    Man, you def need better documentation…

    • Rob,

      This plugin was not written by us, we simply included a few additional lines of code. Rather than steal the credit from the proper source it is expected that a user would visit labitacora.net for the full documentation on using the "Limit Post" plugin.

      • Please let us know how we can make the documentation to this plugin better and let us know where the confusion is. For WordPress beginners it's important to note that you will be looking for a snippet of code that looks like this (the_content) within your theme's php pages. Appearance > Editor will list these pages. Search for the location you would like to use this plugin and change (the_content) to (the_content_limit(320, 'read more…')). Hope this helps a little. Keep in mind that some purchased themes may make it more difficult to locate this snippet or may be using an entirely different method of displaying the content altogether. If you need help please email us.

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