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.

  4. Dawn Commented On

    Thanks for the speedy reply! I'm using the jQuery Easy Accordian (same one here: http://www.madeincima.eu/samples/jquery/easyAccordion/). It's basically just content within tags in the slider panels, and I'm able to display the full content of a page via the normal WordPress syntax, but am not sure how to get it done with Limit-Post..

    • Doc4 Commented On

      Dawn,

      What you're looking for is a WordPress loop calling a page. The code below is working under the assumption there is or will be additional loops on the same page:

      <div id="accordion-1">
       <dl>
        <dt>First slide</dt>
         <dd><h2>This is the first slide</h2>
          <img src="images/monsters/img1.png"/>
          <?php $my_query = new WP_Query('page_id=81');
                     while ($my_query->have_posts()) : $my_query->the_post();
                     $do_not_duplicate = $post->ID; ?>
      
                    <?php get_the_content_limit(700, ''); ?>
                    <?php endwhile; ?>
        </dd>
       </dl>
      </div>

  5. Dawn Commented On

    Hi! This is a really useful plug-in, and I’ve successfully implemented it for displaying my recent posts summary on my website’s home page. I’m kinda lost now though – I want to display limited content from a page into a slider I have on my homepage. Is this possible? I’m a noob at WP so do pardon me if the solution is really straightforward!

    What I have now in my slider div:

    <?php $page_id = 81; $page_data = get_page( $page_id ); 
           $content = apply_filters('get_the_content_limit',$page_data->post_content); 
           echo $content; ?>

    And.. it displays nothing. :( Appreciate any help if you could! TIA!

  6. Maurintius Commented On

    I'm using the default theme of WordPress "Twenty Ten" but I don't know much about scripting so I don't know where to put the code. I think I figured out that it needs to be in the loop.php file but where excactly? Can someone help me?

    Thanks

    grtz

    • Maurintius,

      Every WordPress site is created differently, some have the loop built into pages and as you can see Twenty Ten has it's own loop file. Basically, do a search for "the_content" and replace it with the new code. For example in the case of Twenty Ten: loop.php: Line 122:

      <?php /* How to display all other posts. */ ?>
       <?php else : ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
         <h2 class="entry-title">[block]0[/block]" rel="bookmark"><?php the_title(); ?></a></h2>
         <div class="entry-meta">
          <?php twentyten_posted_on(); ?>
         </div><!-- .entry-meta -->
      
         <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
          <div class="entry-summary">
           <?php the_excerpt(); ?> 
          </div><!-- .entry-summary -->
         <?php else : ?>
          <div class="entry-content">
      
          <!--------------------------------------------------------->
           <?php the_content_limit(320, 'read more...' ); ?>
          <!--------------------------------------------------------->
      
           <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
          </div><!-- .entry-content -->
          <?php endif; ?>

  7. Ohgfh Commented On

    Absolute rubbish don't bother trying to help if you don't leave clear instructions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    • Ohgfh,

      Please take note that this is an "add-on" to another plugin not created by this company, hence the lack of instructions. If you don't want to ask for assistance then please take a moment and read the post.

Tracbacks
  1. How To limit the displayed text length on your Homepage - WordPress Plugin | MindPrompter.com