News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Question on SSI

Started by t3ngu, October 29, 2009, 05:13:49 PM

Previous topic - Next topic

t3ngu

Hello,

Recently I tried implementing SSI on my site to show news from a specific board. The SSI readme told me to put this at the top of the page: <?php require("forums/SSI.php"); ?>

and <?php ssi_boardNews(); ?> where I want to display the news. The problem is, nothing shows up.

I also wasn't told how to set which board is the "news" board, so I'm guessing there's a few steps missing. Could someone help me out please?

Arantor

First up, is the board you're using for news visible to guests?

t3ngu

Yes it is, and the news on the front page is supposed to be, too.

Arantor

And I take it guests can browse the forum?

You should be able to select the board by simply adding the board's number in the brackets, e.g. ssi_boardNews(1);

t3ngu

Derp

That did it, thanks you sir.

t3ngu

#5
Sorry for the double post, but I have a new question concerning SSI.

http://img137.imageshack.us/img137/8233/ssiproblem.jpg

Is there a way to edit the way the latest posts is displayed? As you can see, it's all jumbled up.

And I'm assuming that if I wanted the latest posts from certain boards, I can put them in the parenthesis? Are they separated by commas if there are multiple boards?

Arantor

Modifying the display output is reasonably easy to do, either by modifying your stylesheet to suit or by producing the output in a different way.

As for multiple boards, no, boardnews doesn't support that and would require a custom modification to its code. That's been covered more than once in the forum though.

t3ngu

I see, do you happen to have a link to the custom mod?

I ended up editing SSI.php to change out the posts are outputted.

I editted it to this:
Quote<table border="0" class="ssi_table">';
   foreach ($posts as $post)
      echo '
         <tr>
            <td align="top" valign="top" nowrap="nowrap">
               [', $post['board']['link'], ']
            </td>
                        <td align="right" nowrap="nowrap">
               ', $post['time'], '
            </td>
         <tr>
            <td valign="left">
               &nbsp&nbsp -<a href="', $post['href'], '">', $post['subject'], '</a>
               ', $txt['by'], ' ', $post['poster']['link'], '
               ', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '
            </td>
         </tr>';
   echo '
      </table>';

And the results were nice, but I found there's a problem with threads that have long titles.
http://img229.imageshack.us/i/ssiproblem2.jpg/

Is there a way to limit the amount of characters displayed, then cut it of with "..."?

And do you know why it cuts off at a certain point? I want to change it so the latest posts fit within the box, but editting the height or padding of the box didn't seem to affect it. Actually this seems like a question that's a problem with my css rather than SSI... please answer it if you can, but if not, I'll try to figure it out myself.

Arantor

I don't have a link to it because it's not an existing mod AFAIK (though searching the mod site might help); it's a modification of the existing code.

We don't ever recommend modifying SSI.php itself when there are alternative methods for doing this but if it works for you...

I can't tell you why it cuts off; I don't know. But you can use $post['short_subject'] instead of $post['subject'] for a shortened version.

t3ngu

Ok, thanks. I figured out why it was getting cut off.

As for not modifying SSI.php, what would you recommend I do instead? That's the file that decides how the output is displayed, so I figured it's the only way to edit it.

Arantor

Most of the functions support the last parameter being stated as 'array' or 'echo'. echo means output, array means return the information in an array, meaning you can have it display using exactly whatever code you want, with any tags.

t3ngu

Hm, so how would I display it with an array like the method in my quoted script? I'm quite new to php and not familiar with this.

Also, about showing new posts from a specific board - I found this:
http://www.simplemachines.org/community/index.php?topic=72832.msg1803884#msg1803884
but I'm not sure how it's supposed to be implemented. Do I replace <?php ssi_recentPosts(); ?>   with
$array = ssi_boardNews(59, 10, null, null, 'array');

foreach ($array as $topic)
   echo '<a href="', $topic['href'], '">', $topic['subject'], '</a><br />';

this? Or do I put it in somewhere between the PHP tags?

Arantor

You put that code inside <?php and ?>

Like so:
<?php $array ssi_boardNews(5910nullnull'array');

foreach (
$array as $topic)
   echo 
'<a href="'$topic['href'], '">'$topic['subject'], '</a><br />'?>


Though, that'll pull 10 items from board 59 and simply display a list of topics and link to them, but that's the general form.

t3ngu

So I'm trying to display it in an array in the format that I posted before.

<?php $array ssi_boardNews(310nullnull'array');

   echo 
'
<table border="0" class="ssi_table">'
;
foreach ($array as $topic)
echo '
<tr>
<td align="top" valign="top" nowrap="nowrap">
['
$post['board']['link'], ']
</td>
<td align="right" nowrap="nowrap">
'
$post['time'], '
</td>
<tr>
<td valign="left">
'
<a href="', $topic['href'], '">', $topic['subject'], '</a><br />';
'
$txt['by'], ' '$post['poster']['link'], '
'
$post['new'] ? '' '<a href="' $scripturl '?topic=' $post['topic'] . '.msg' $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' $settings['lang_images_url'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>''
</td>
</tr>'
;
echo '
</table>'
;
   
?>


I copied this over from the editted SSI.php, but get this error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in (file) on line 126 (               '<a href="', $topic['href'], '">', $topic['subject'], '</a><br />';)

Just pasting your code works, but it only shows the thread title with no time or poster (forum category isn't really needed, but would be nice to include if I have space).

I'm guessing I screwed up by trying to include the table format, but I'm not sure how to show post it in an array while making it look good.

Arantor

Quote from: t3ngu on October 31, 2009, 03:01:30 AM
I copied this over from the editted SSI.php, but get this error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in (file) on line 126 (               '<a href="', $topic['href'], '">', $topic['subject'], '</a><br />';)

Take off the ' at the start of that line.

Quote
Just pasting your code works, but it only shows the thread title with no time or poster (forum category isn't really needed, but would be nice to include if I have space).

Like I said it would.

t3ngu

Alright, I'm getting close.

<?php
$array 
ssi_boardNews(310nullnull'array');

   {
      echo 
'
<table border="0" class="ssi_table">'
;
foreach ($array as $topic)
echo '
<tr>
<td align="top" valign="top" nowrap="nowrap">
['
$topic['board']['link'], ']
</td>
<td align="right" nowrap="nowrap">
'
$topic['time'], '
</td>
<tr>
<td valign="left">
'
$topic['href'], ''$topic['short_subject'], '</a>
'
$txt['by'], ' '$topic['poster']['link'], '
'
$topic['new'] ? '' '<a href="' $scripturl '?topic=' $topic['topic'] . '.msg' $topic['new_from'] . ';topicseen#new" rel="nofollow"><img src="' $settings['lang_images_url'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>''
</td>
</tr>'
;
echo '
</table>'
;
}
?>


It now shows

[]      October 29, 2009, 08:25:49 PM
http://www.site.com/forums/index.php?topic=5.0 by poster

It SHOULD be

[Forum Category]      October 29, 2009, 08:25:49 PM
Thread name by poster

Is there a reason [', $topic['board']['link'], '] and ', $topic['href'], '', $topic['short_subject'], '</a> aren't working?

Arantor

Well, $topic['href'] is literally just the URL to the topic.

You'd need to put it in an <a> tag. As for $topic['short_subject'], check in SSI.php that that is being produced.

Also check in SSI.php that ['board']['link'] is being produced.

t3ngu

I haven't changed SSI.php there, only the part where it's displayed wth "echo". It should still be produced, I'm pretty sure it's this line:

// Build the array.
$posts[] = array(
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),


and
'short_subject' => shorten_subject($row['subject'], 25),


I also added the <a> tags, but it's still not displaying 'short_subject'.

Arantor

Weird. Any errors in the forum error log? (SSI does tend to push them there under some occasions)

t3ngu

Nope, nothing in there. For the record here's the code again:
<?php
$array 
ssi_boardNews(310nullnull'array');

   {
      echo 
'
<table border="0" class="ssi_table">'
;
foreach ($array as $topic)
echo '
<tr>
<td align="top" valign="top" nowrap="nowrap">
['
$topic['board']['link'], ']
</td>
<td align="right" nowrap="nowrap">
'
$topic['time'], '
</td>
<tr>
<td valign="left">
<a href="'
$topic['href'], '">'$topic['short_subject'], '</a><br />
'
$txt['by'], ' '$topic['poster']['link'], '
'
$topic['new'] ? '' '<a href="' $scripturl '?topic=' $topic['topic'] . '.msg' $topic['new_from'] . ';topicseen#new" rel="nofollow"><img src="' $settings['lang_images_url'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>''
</td>
</tr>'
;
echo '
</table>'
;
}
?>


Could it be the tables causing it to act weird? I'm wondering if there's a way to display it the same way without tables. The format would be:

[Forum Category]                                             Date, time
Thread name by Username

Advertisement: