Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 26 Jul 2010, 03:29
Kyle55155 Kyle55155 is offline
 
Join Date: Mar 2010
Need a little code

I'm using this code to display forum thread titles on a custom vb page:
<script type="text/javascript" src="external.php?forumids=111,112,113,114,115,133,148,154&type=js"></script>
<script language="" type="text/javascript">
<!--
for (x = 0; x < 3; x++)
{
document.writeln("<a href=\"showthread.php?t="+threads[x].threadid+"\">");




document.writeln("<b>"+threads[x].title+"</b><br />");



document.writeln("</a>");
document.writeln("Posted "+threads[x].threaddate+" at "+threads[x].threadtime+" by "+threads[x].poster+"<br />");
}
//-->
</script>


I'm trying to figure out how to limit the number of characters that are displayed in the title.

document.writeln("<b>"+threads[x].title+"</b><br />");

I tried inserting this code inside the javascript but I can't seem to get it to work
<?php
$len = 30;

if (strlen($thread['title']) > $len) {
$thread['title'] = substr($thread['title'],0,$len);
$thread['title'] .= "...";
} else {
$thread['title'] = $thread['title'];
}
?>

Ideally I would like to limit the character length of threads.title and append a ... when it gets cut off.

Any coders out there have a solution for me?

Thanks
Reply With Quote
  #2  
Old 26 Jul 2010, 04:29
Guest190829
Guest
 
The problem is you are trying to use PHP within javascript; luckily, javascript provides the same string manipulation functions that you need. The following should work (I don't know if you explicitly need to declare the string as an object or not, let me know if it isn't working):


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #3  
Old 26 Jul 2010, 07:32
Kyle55155 Kyle55155 is offline
 
Join Date: Mar 2010
thanks Danny,

I entered your code exactly as you posted but it didn't work. I was able to get the following code to work:

<script language="" type="text/javascript">
<!--
for (x = 0; x < 3; x++)
{
document.writeln("<a href=\"showthread.php?t="+threads[x].threadid+"\">");

var tread = threads[x].title;

if (tread.length > 30)
{
document.writeln(tread.substring(0,30))
document.writeln("...&nbsp;")
}
else
{

document.writeln(tread)
document.writeln("&nbsp;")

}

document.writeln("</a>");
document.writeln("Posted "+threads[x].threaddate+" at "+threads[x].threadtime+" by "+threads[x].poster+"<br />");
}
//-->
</script>

I'm sure it could be cleaned up.

One thing I still need is code that will count out to the character limit and then break at the end of the closest word such that the last word in the string is not a partial word.

Any idea how to add that?

Thanks
Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Profile Enhancements URL, BB code & Embed code information under album images C.Birch vBulletin 3.7 Template Modifications 58 07 Apr 2008 18:04



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 00:19.

Layout Options | Width: Wide Color: