WordPress.org

Ready to get started?Download WordPress

Forums

Limit amount of words displayed without using the_excerpt or <!--more--> (5 posts)

  1. desmondo
    Member
    Posted 5 years ago #

    Hi all,

    I've been searching for this for hours and surprisingly come up with nothing. I am using the great "more fields" plugin here:

    When I output the content, I want to have a landing page with the intro text for each post. I would like to just grab the first 50 words of text or so from the post and show them only with at "read more" link to the post.

    Is there a way to control the amount of words output on any type of content? My line of code is:
    <?php meta('body-text'); ?>

    Any help would be greatly appreciated.

  2. MichaelH
    Member
    Posted 5 years ago #

    From The Excerpt Reloaded by Kaf:

    the_excerpt Reloaded, when a post does not contain an excerpt, displays the contents of the post (typically abbreviated), which can be customized on which HTML tags to allow, length of the excerpt (in words), "more..." link, and filtering type.

    If you use that plugin, please review:
    http://robsnotebook.com/the-excerpt-reloaded
    http://wordpressgarage.com/plugins/the-excerpt-reloaded/

  3. desmondo
    Member
    Posted 5 years ago #

    Thanks for your prompt reply Michael, I really appreciate it.

    I have installed the excerpt_reloaded plugin, but I think the problem is that it is applied to the_content field. In this instance, I would like to be able to apply it to another field I have created using the "more fields" plugin.

    Which was this one:
    <?php meta('body-text'); ?>

    Do you know if there is a way of doing that?
    Cheers

  4. MichaelH
    Member
    Posted 5 years ago #

    The more fields plugin author has examples of code at http://labs.dagensskiva.com/plugins/more-fields/#id3

    Something like:

    <?php
      if ($bodytext = get_meta('body-text'))
      echo 'Text: ' . $bodytext;
    ?>
  5. desmondo
    Member
    Posted 5 years ago #

    Thanks for your reply Michael. I couldn't get is working with the excerpt, so I got the PHP developer here to help me out. Here is what he came up with:

    <dl>
    <?php $temp_query = $wp_query; ?>
    <?php if (have_posts()) : ?>
    <?php query_posts(array(
    	'post_status' => 'publish',
    	'static' => true,
    	'child_of'=>'254,271,228,237,34',
    	'post_per_page' => '2',
    	'showposts' => '2',
    	)); ?>
    <?php static $ctr = 0; 	?>
    <?php while (have_posts()) : the_post(); ?>
    	<?php if ($ctr == "2") { break; } else { ?>
    	<dt><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></dt>
    	<dd>
    		<div class="thumbnail"><?php meta('thumbnail-graphic'); ?></div>
    		<?php if ($introtext = get_meta('intro-text')){
    			if (strlen($introtext) > 55){
    				$words = str_word_count($introtext, 2);
    				$pos = array_keys($words);
    				$introtext = substr($introtext, 0, $pos[55]) . '...';
    			}
    			echo $introtext;
    		}
    		?>
    		<p><a class="arrowLink" href="<?php the_permalink() ?>">Read more</a></p>
    	</dd>
    	<?php $ctr++; }?>
    <?php
    endwhile;
    endif;
    $wp_query = $temp_query;
    ?>
    </dl>

    Works a treat

Topic Closed

This topic has been closed to new replies.

About this Topic