1
kymseen
hack for shortening content text with "..."
  • 2006/9/16 19:26

  • kymseen

  • Just popping in

  • Posts: 23

  • Since: 2006/9/11


I am using the wordpress module for XOOPS right now

https://xoops.org/modules/repository/singlefile.php?cid=4&lid=1420

I have the content block on the top page as to display the recent posted blogs. I didn't want to show the whole entry text, only the first few lines... So I was wondering if I could shorten the text automatically with a certain code.

I searched through and I know there is...

xoops_substr

and PHP code mb_strimwidth which should help me with this case. I have searched through forums and tutorials but found nothing.

Has anyone done this to their wordpress module or any other module???

any hints or tips would be great!!

thank you!!

2
jensclas
Re: hack for shortening content text with "..."

Sorry I can't help with your question but I must ask you not to double post - your second of the same has been removed.

3
iHackCode
Re: hack for shortening content text with "..."

this is a XOOPS function.
xoops/include/functions.php
/**
* Returns the portion of string specified by the start and length parameters. If $trimmarker is supplied, it is appended to the return string. This function works fine with multi-byte characters if mb_* functions exist on the server.
*
* @param    string    $str
* @param    int       $start
* @param    int       $length
* @param    string    $trimmarker
*
* @return   string
*/
function xoops_substr($str$start$length$trimmarker '...')
{.. 
blah blah and a whole bunch of code..


wow. i just woke up.. i hope this makes sense.

the function truncates the string specified and if its more then the specified length then it puts a ... at the end.

example: (just a basic example)
$str being some string i pass to the function
0 the starting position
25 the length of the text.. it tests if it more than 25.. if yes then it adds an '...' if its not then it just shows the text.. and you can also specify to show something else besides '...' in the following example it left it out and the the fuction automatically adds the last parameter
$mytext xoops_substr($str,025);


example from the news module..but im not sure on which file to include.
$myts =& MyTextSanitizer::getInstance();
$news['teaser'] = xoops_substr(strip_tags($myts->displayTarea($story->hometext)), 0$options[3]+3);

--
there is also a way to truncate strings with smarty.
link to GIJOE's Site
Example:
<{$news.title|xoops_substr:"0":"20"}>


edit:wow just noticed there is also and explanation on what the function does in that comment.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

4
kymseen
Re: hack for shortening content text with "..."
  • 2006/9/20 7:35

  • kymseen

  • Just popping in

  • Posts: 23

  • Since: 2006/9/11


bandit-x, thank you for the info!

but I was unsuccessful on putting the code in...
I assume the method will work with news modules, could someone tell me where to put the codes in?? If anyone was successful with this kind of hack.

I am using news1.15 fileup right now.

Also, I am very curious if these codes, xoops_substr will work on other non-xoops defsult modules(for example, wordpressME)???

any help would be great!!
I am very LOOOOOOOST

5
iHackCode
Re: hack for shortening content text with "..."

this is for the wordpress me module..

edit the block template for the content block.

file: wp_block_contents.html
<{if $block.style != ""}>
<
style type="text/css">
    
style>
<{/if}>
<
div id='<{$block.divid}>'>
<{if 
$block.use_theme_template == 0}>
  <{foreach 
item=content from=$block.contents}>
    <{if 
$content.date != ""}>
        <
h2><{$content.date}>h2>
    <{/if}>
        <
div class="post">
            <
h3 class="storytitle" id="post-<{$content.date}>"><a href="<{$content.permlink}>" rel="bookmark" title="Permanent Link: <{$content.title}>"><{$content.title[color=CC0000] |xoops_substr:"0":"10"[/color]}>a>h3>
            <
div class="meta">


i added whats in red.. 10 being the max length of the title.. i had a title called "really really really reallly really long title" it became "really ..."
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

6
kymseen
Re: hack for shortening content text with "..."
  • 2006/9/21 15:14

  • kymseen

  • Just popping in

  • Posts: 23

  • Since: 2006/9/11


bandit-x, Thank you

I tried the putting in the code but no luck...
hmmmmm...

I couldn't find the wp_block_contents.html
instead I found wp_contents.html.

I found the same code inside, so I assume that wasn't the problem...

I need to do a little more research...

7
iHackCode
Re: hack for shortening content text with "..."

wp_block_contents.html is in the blocks folder 'blocks/wp_block_contents.html'

if you are using the default template. if you edit those files directly you will have to update the module so the changes in the template shows up.. but it also might change that module's settings
or.
if you cloned the default template set. you can just edit the block template via the template admin.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

8
kymseen
Re: hack for shortening content text with "..."
  • 2006/9/23 17:51

  • kymseen

  • Just popping in

  • Posts: 23

  • Since: 2006/9/11


sorry, Bandit-x but there are only php files under the blocks file. wp_contents.php is the only one relating content block.

hmmmmmm.....

I searched through some tutorial books and there was this one way to shorten texts, with the Smarty modifier.mbtruncate.php. this is a smarty plugin that modified the original modifier.truncate.php into megabyte format, since I am using Japanese.

the directions were to add the php plugin and enter the code in the html

so under wp_contents.html, I added


<{$content.body|mbtruncate:100}>






still no luck???

What do you think about this method??

am I putting the code in the wrong place?
Are there more things that I need to change??

Thanks in advance.



9
iHackCode
Re: hack for shortening content text with "..."

sry i wrote the wrong directory. its in the 'modules\wordpress\templates\blocks' directory
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

10
kymseen
Re: hack for shortening content text with "..."
  • 2006/10/1 17:23

  • kymseen

  • Just popping in

  • Posts: 23

  • Since: 2006/9/11


hello,

I was successfull after...

under wp_contents.html, I added


<{$content.body|mbtruncate:100}>






AND
set preferences for "use templates under themes directory" to "NO" meaning to not use the content_block-template.php.

This solved my problem but made me force to not use the templates under themes directory. I know that there should be another way to use xoops_substr from content_block-template.php.

hmmm...

anyone done it through content_block-template.php??
I want to also shorten content text in the wordpress module page and I don't know which file to edit.

Login

Who's Online

270 user(s) are online (108 user(s) are browsing Support Forums)


Members: 0


Guests: 270


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits