Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Character/Word Display Limit

    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:

    Code:
    <?php echo nl2br(get_post_meta($post->ID,'proprty_feature',true));?>
    Any ideas on how to do this?

    Thank you

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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=word...th&btnG=Search

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I've got this far:

    I have this code:

    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

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,344
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    .'<a href="<-URL HERE->">Read more</a>'
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Where do I put that in relation to the code I have written?

    It surely can't be that simple?

  • #6
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The link will be <a href="<?php the_permalink(); ?>"> ...more</a> but I can't seem to get it to work

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •