Jump to content

Recommended Posts

An issue I've lived with too long (not a coder - self-taught to a point but I cant properly solve this one)

My word press has a plugin that delivers a text output from a self-publish form-field that I need to restrict.

"Tagline" in code below.  between -->   <--

           <?php if($property['custom_attribute_overview'] || $property['tagline']): ?>
                <li class="property_tagline">
                    <?php if($property['custom_attribute_overview']): ?>
                        <?php echo $property['custom_attribute_overview']; ?>
                    <?php elseif($property['tagline']): ?>
-->             <?php echo $property['tagline'];  ?>     <--
                    <?php endif; ?>
                </li>
            <?php endif; ?> 

I'd be happy if it either simply truncated after x characters or ended ... after x characters or some specified length

Any guidance would be appreciated.

Thank you. 

Link to comment
https://forums.phpfreaks.com/topic/314931-trim-or-limit-characters-in-echo-output/
Share on other sites

@ Barand, Thank you,

I tried it on two sites. One resulted in a fatal error message (was able to undo) . The other site had no impact on another.... 

(I cant explain why all the php tags to be honest - its an older plugin originally from 2013 / 14 thereabouts. I got myself up to speed enough to customize some of the lines and code in my own site, but never picked up enough to see the efficiency or inefficiency of the original coding or excess php tags.. 

The plugin was or is wp-property - this is from the propertyoverview.php setup for listing properties in a list or gallery format. 

I do appreciate the the info and guidance offered. (The image displays the issue I am trying to resolve).

(Perhaps I am better to try and truncate from the source text field)

 

PHP Truncate QUestion Sample.jpg

@ Barand, Thank you,

I tried it on two sites. One resulted in a fatal error message (was able to undo) . The other site had no impact on another.... 

(I cant explain why all the php tags to be honest - its an older plugin originally from 2013 / 14 thereabouts. I got myself up to speed enough to customize some of the lines and code in my own site, but never picked up enough to see the efficiency or inefficiency of the original coding or excess php tags.. 

 

The plugin was or is wp-property - this is from the propertyoverview.php setup for listing properties in a list or gallery format. 

I do appreciate the the info and guidance offered. 

(Perhaps I am better to try and truncate from the source text field)

 

@maxxd Thank you for the question of clarity. 

Re too much content or overflowing:  It is that it is showing too much content (there is no limit on the text  input field that ). So self-publishers input a paragraph into what should only be a 5 or 6 word headline... (I believe I can css the overflow)

Open to options (restrict input source field or the public facing side). Any guidance is appreciated. 

 

If you're specifically looking for a title attribute and not the post body itself, I'd look at adding a maxlength attribute to your input field. You'll want to validate and, if necessary, truncate the text on the server side as suggested by Barand (or just reject the input wholesale) because there are ways around the browser, but it's a start.

Admittedly from what I see the title doesn't seem to be the issue in the screencap you posted, so I'll say if I'm misunderstanding what you're calling things and you're referring to what is typically the post body you'll probably want the WP-specific the_excerpt function.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.