...

View Full Version : Character/Word Display Limit



Jallen057
01-20-2012, 02:02 PM
I'm no expert on PHP so I need a little help.

I am trying to limit a wordpress custom field from displaying more than 150 characters, if it goes over that, I want a 'Read More' link to display.

Here is what I want limited:


<?php echo nl2br(get_post_meta($post->ID,'proprty_feature',true));?>

Any ideas on how to do this?

Thank you

mlseim
01-20-2012, 02:36 PM
For WordPress issues, they have what is called CODEX, like you gave us in your example.

There are various methods ... by character, by word, and what appears after it, etc.

See if any of these pertain:
https://www.google.com/search?q=wordpress+limit+excerpt+length&btnG=Search

Jallen57
01-20-2012, 07:02 PM
I've got this far:

I have this code:


<?php $trim_length = 10; //desired length of text to display
$custom_field = 'proprty_feature';
$value = get_post_meta($post->ID, $custom_field, true);
if ($value) {
echo rtrim(substr($value,0,$trim_length));
}
?>

Which works great, however if it does have to chop the text, I want it to display a 'read more' link, how can I do this?

Thank you

tangoforce
01-20-2012, 08:07 PM
.'<a href="<-URL HERE->">Read more</a>'

Jallen57
01-20-2012, 08:10 PM
Where do I put that in relation to the code I have written?

It surely can't be that simple?

Jallen057
01-20-2012, 08:56 PM
The link will be <a href="<?php the_permalink(); ?>"> ...more</a> but I can't seem to get it to work :(

mlseim
01-20-2012, 09:08 PM
Here's an example from one of my WordPress sites ....

<?php the_excerpt(); ?>
</div>
<!--/post-excerpt -->
<div class="clr"></div>
<div class="post-leav"><a href="<?php the_permalink(); ?>" title="<?php _e('Read More'); ?>">
<?php _e('read more'); ?>
&raquo;</a></div>


Yours will look somewhat different, but you can see how the 'read more' is put in.


.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum