View Full Version : Character/Word Display Limit

01-20-2012, 01: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

01-20-2012, 01: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:

01-20-2012, 06: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

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

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

It surely can't be that simple?

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

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

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

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