[PAID] Requesting a mod to truncate long text

Started by Grammy, February 12, 2025, 07:02:48 AM

Previous topic - Next topic

Grammy

I am using 2.1.4 Default.  I'm not sure if this sort of thing actually requires a mod, or if I'm better off in the [PAID] Help wanted board (although I'm happy to pay in either location).  :)

Members are using a designated board to "blog" on (because I was able to get SMFBlog running smoothly in 2.1.4.) It uses the forum boards.  All is fine, until you begin browsing through the blogs. The entire blog shows up, title by title, and those stinkin' things go on forever!  I'd love to be able to truncate long narratives and posts once they reach a certain word or character length and since the blog is really utilizing the forum's boards and posting functions, I thought a mod to truncate could be useful across the forum and would happily also affect the blogs.

Is that a possibility? 

vbgamer45

Here is some code that limits to 128 characters. replace $body with the variable needed.
if ($smcFunc['strlen']($body) > 128)
$body = $smcFunc['substr']($body, 0, 128) . '...';
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Grammy

@vbgamer45  Thank you!  Can I ask, please if this is to be placed in a template file?  I wasn't sure where to put it (but I'm not afraid to blow up my test forum; the louder and the more smoke, the better, ha!).  :)

shawnb61

Note you can restrict max post size in Admin| Forum | Posts and Topics | Post Settings.

This will limit the length of posts going forward.
A question worth asking is born in experience & driven by necessity. - Fripp

Grammy


Quote from: shawnb61 on February 12, 2025, 08:28:07 AMNote you can restrict max post size in Admin| Forum | Posts and Topics | Post Settings.

This will limit the length of posts going forward.


Thanks, @shawnb61  I guess I want the bloggers to be able to wax eloquent without stifling them, but I also want to spare others who are just browsing to not have to keep scrolling and scrolling to get to the next blog.  :D

Doug Heffernan

What blog mod are you using? If you want to affect the blogs only, find the function that displays the blogs and you can add something like this:

if (strlen($row['blog_title']) > 27)
{
      $row['blog_title'] = substr($row['blog_title'], 0, 27) . "...";
}

And replace the variables, blog title field name and the titles characters accordingly.

shawnb61

But truncating their text is not allowing them to wax eloquent...  Once truncated, that text is lost.
A question worth asking is born in experience & driven by necessity. - Fripp

Grammy

Quote from: Doug Heffernan on February 12, 2025, 08:31:37 AMWhat blog mod are you using? If you want to affect the blogs only, find the function that displays the blogs and you can add something like this:

if (strlen($row['blog_title']) > 27)
{
      $row['blog_title'] = substr($row['blog_title'], 0, 27) . "...";
}

And replace the variables, blog title field name and the titles characters accordingly.


Hi, @Doug Heffernan

I got SMFBlog running really well on 2.1.4 and I just want to be able, which clicking on Available Blogs to see truncated versions of them, instead of having the full blog show on the listings.  Let me try that code, thank you!

Doug Heffernan

Quote from: shawnb61 on February 12, 2025, 08:33:10 AMBut truncating their text is not allowing them to wax eloquent...  Once truncated, that text is lost.

The whole title will still be available on the blog view page.

Grammy

It's actually the very long blog (the whole blog appears in the listings for available blogs) that I'd like to shorten and, as shawnb61 pointed out, I'm using the wrong term.  I don't want to lose the text, just make it so that if you want to actually read the whole long blog, you have to click on the blog's title to go to it and read it in its entirety. 

Grammy

@vbgamer45 @Doug Heffernan @shawnb61

I guess what I really need is a "read more" mod?  I don't see one, searching.  But you see that feature on web sites all the time, after a teaser paragraph.  I suppose that's what I need. I'm sorry for using "truncate" incorrectly.

Doug Heffernan

Quote from: Grammy on February 12, 2025, 08:37:03 AMI don't want to lose the text, just make it so that if you want to actually read the whole long blog, you have to click on the blog's title to go to it and read it in its entirety. 

That's precisely what the code I posted above will do. The blog title will not be lost at all. It will simpley be shortened, as you requested, on the titles page, but it will be fully shown when users go to it and read it in its entirety.

Kindred

#12
Doug -- I think that the blog mod actually shows the WHOLE POST

Grammy doesn't want to truncate the title -- If I have understood correctly,  she wants the post to show the first 100 characters and then <read more...>   or something like that
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Grammy

This particular test board blog is very short but on the main board, they get huge.  (Screenshot)  it's actually the blog contents, after clicking "Available Blogs" and clicking on someone's name that I'd like to shorten (or preview) rather than the title.  I'm sorry I'm screwing this all up. 

You cannot view this attachment.

Grammy

Quote from: Kindred on February 12, 2025, 08:48:02 AMDoug -- I think that the blog mod actually shows the WHOLE POST

Grammy doesn't want to truncate the title -- If I have understood correctly,  he wants the post to show the first 100 characters and then <read more...>   or something like that

I'm a "she".   :D   But yes, that's what I want to do.  I put a screenshot on my last reply.   I thought there used to be an old "Read More" mod but I can't find it.

Doug Heffernan

Quote from: Kindred on February 12, 2025, 08:48:02 AMDoug -- I think that the blog mod actually shows the WHOLE POST

Grammy doesn't want to truncate the title -- If I have understood correctly,  he wants the post to show the first 100 characters and then <read more...>   or something like that

AH ok. I read it wrong then.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Grammy

I got a "sorta kinda" result just by whipping up a scrap file:  HERE

But, of course, I actually entered a long bunch of Lorem Ipsum in the string and put a url to the test forum in the anchor tag.  I can't do that for every blog, so I guess I need to figure out how to get the string to reflect all blogs and the anchor to be whatever ID_board that blog is posted on.  But first, I think I'll split the atom, to relax.   :(

$string = 'Long string of text greater than 500 characters';

echo substr($string, 0, 500).'... <br /><br /><a href="">Read More</a>';

Advertisement: