miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /  
 

First 10 words of message in the Recent Topics list

 
 
Page  Page 1 of 4:  1  2  3  4  Next »

Author tom322
Active Member
#1 | Posted: 30 May 2006 18:22 
Hello,

Is there a simple way to include the first X words from the first post in the latest discussions below the title of each topic?

For example the last discussions of this topic should look like this:

First words of post in the latest discussions
Is there a simple way to include the first...


Thanks:)

Tom

Author realitybytes
Partaker
#2 | Posted: 30 May 2006 18:26 
//$textLd=1; Available from 2.0 RC4, setting $textLd=1; or $textLd=2; you will get {$lastPostText} variable available in latest discussions section on the first page (templates/main_last_discuss_cell.html). If set to 2, all HTML formatting is removed from the post text, and you can use it in <acronym> tag, for example. If set to 1, post text is left as it is.

Author tom322
Active Member
#3 | Posted: 30 May 2006 18:29 
Oh, OK -- but I think it will show the last poster's text instead of the first few words of the first post... I would like the first few words of the first post in this topic to always show....

Author Team
8-)
#4 | Posted: 30 May 2006 19:56 
tom322
if you sort by new posts it is, but if you sort by New Topics it should be use the first post text.

if you want to show it even in case of New Posts sort type in the bb_func_ldisc.php try changing:

if($row=db_simpleSelect(0, $Tp, 'poster_id, poster_name, post_time, topic_id'.$textLdSql, '', '', '', 'post_id DESC'))

to:

if($row=db_simpleSelect(0, $Tp, 'poster_id, poster_name, post_time, topic_id'.$textLdSql, '', '', '', 'post_id ASC'))

Author tom322
Active Member
#5 | Posted: 30 May 2006 20:20 
Hi Team,

I sort by new posts -- but I think it doesn't show the first few words of the first post ("if you sort by new posts it is") - unless I'm looking at the wrong place or something...

[added] I think you meant it shows the first words from the topic TITLE - but I also need to show the first few words from the first message (post) in that topic too :)[/added]

Thank you,
tom

Author realitybytes
Partaker
#6 | Posted: 30 May 2006 21:26 
Have you added {$lastPostText}
to main_last_discuss_cell.html

I have it working here but it seems to be putting the entire post in the cell.

Author tom322
Active Member
#7 | Posted: 30 May 2006 21:36 
Have you added {$lastPostText}
to main_last_discuss_cell.html

I have it working here but it seems to be putting the entire post in the cell.


Yes, I tried it before but as you say it puts the entire post (I could still use it to do somethinge else too but only if it put a few words, not the entire post - any ideas how to do that would be appreciated).

However, as I wrote above - I'd also like to have the first few (maybe 10) words of the first post in a particular topic, not the last post.

tom

Author realitybytes
Partaker
#8 | Posted: 30 May 2006 21:55 
I have a solution

it requires adding to bb_func_ldisc.php

$lptxt = substr($lptxt, 0, 25) . "...";

under

$lptxt=($textLd==1?$pVals[$topic][3]:strip_tags($pVals[$topic][3]));

change 25 to the desired number of characters

Or change it to a variable $textLdLnth = x; in setup_options if you wish to make for easier testing
and use

$lptxt = substr($lptxt, 0, $textLdLnth) . "...";

It will limit the ammount of characters it displays and add ... to the end

Author tom322
Active Member
#9 | Posted: 30 May 2006 22:10 
realitybytes
Wow, that's exactly what I needed (at least as far as the second question is concerned - I'm still not sure how to get the first words of the first - not the last - post).

(ps. I'm not sure if there's a way to strip the number of words instead of characters so that there are X first words shown instead of X characters? Also, how to make sure there's no formatting left - currently when there's a new line, it includes it and it's better if it doesn't) .

Thanks!

tom

Author realitybytes
Partaker
#10 | Posted: 30 May 2006 22:27 
explode " "

so from above would be

$exlptxt = explode(" ", $lptxt);

You then have each word available in an array

$exlptxt[0] //first word
$exlptxt[1] //second word

and so on. However you might run in to prolems if somebody spams rubbish without spaces you will end up with one long text.

Also you will need to decide how many words you wish for and idealy need to create some conditions as to how to deal with fewer than desired words posted.

To rule out the above you could use a combination of words and chars

So you will need to count the words available

$words = count(explode(" ", $lptxt));
if($words < x){
do;
}
else
{
$exlptxt = explode(" ", $lptxt);
$lptxt = $exlptxt[0]." ".$exlptxt[1]." "$exlptxt[02]; //so on
$varlength = strlen($lptxt);
if($varlength > x){
$lptxt = substr($lptxt, 0, x) . "...";
}
else {
$lptxt .= "...";
}

Something like that working from top of my head now as I removed all the previous from my board

Hope you understand it.
replace the x(s) to suit your needs

Author tom322
Active Member
#11 | Posted: 30 May 2006 22:38 
Thank you! So I should put the code below (changing X to a number):

$words = count(explode(" ", $lptxt));
if($words < x){
do;
}
else
{
$exlptxt = explode(" ", $lptxt);
$lptxt = $exlptxt[0]." ".$exlptxt[1]." "$exlptxt[02]; //so on
$varlength = strlen($lptxt);
if($varlength > x){
$lptxt = substr($lptxt, 0, x) . "...";
}
else {
$lptxt .= "...";
}



under $lptxt=($textLd==1?$pVals[$topic][3]:strip_tags($pVals[$topic][3])); in bb_func_ldisc.php file, correct..?

tom

Author realitybytes
Partaker
#12 | Posted: 30 May 2006 22:45 
not quite,

It needs a little work

as in how to deal with posts that dont contain enough words

so if it is less than then count the words

and have a loop to create the $exlptxt array

for x < $words

do

Got something on right now so cant test anything out

Author tom322
Active Member
#13 | Posted: 30 May 2006 22:51 
I don't know php well, but I think if x < $words, then let $words=x (so if there are less than x words, let it shows all available words). Or something like that...:}

Author realitybytes
Partaker
#14 | Posted: 30 May 2006 23:16 
yes you are right wasnt thinking straight

so can scrap the if else and just use

$words = count(explode(" ", $lptxt));
if $words > x {
$exlptxt = explode(" ", $lptxt);
$lptxt = $exlptxt[0]." ".$exlptxt[1]." ".$exlptxt[02]; //so on
$varlength = strlen($lptxt);
if($varlength > x){
$lptxt = substr($lptxt, 0, x) . "...";
}
else {
$lptxt .= "...";
}
}

Author tom322
Active Member
#15 | Posted: 30 May 2006 23:52 
Thanks.. But I'm getting some errors.

Let me conclude what steps exactly I should do - if you could confirm it's correct that would be great. Let's assume I want 10 words to show and $varlenght=20:

1. Add

$textLdLnth = 10;

to setup_options.php.

2. Add

$lptxt = substr($lptxt, 0, $textLdLnth) . "...";

$words = count(explode(" ", $lptxt));
if $words > $textLdLnth {
$exlptxt = explode(" ", $lptxt);
$lptxt = $exlptxt[0]." ".$exlptxt[1]." ".$exlptxt[02]; //so on
$varlength = strlen($lptxt);
if($varlength > 20){
$lptxt = substr($lptxt, 0, 20) . "...";
}
else {
$lptxt .= "...";
}
}

under

$lptxt=($textLd==1?$pVals[$topic][3]:strip_tags($pVals[$topic][3]));

in bb_func_ldisc.php file.

-----

BTW - I'm not sure what $varlenght is exactly to show...

Thank you,

tom

Page  Page 1 of 4:  1  2  3  4  Next » 
Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /
 First 10 words of message in the Recent Topics list
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Check out the Captcha add-on: protect your miniBB-forums from the automated spam and flood.


  ⇑